Git Product home page Git Product logo

service-cli's Introduction

CLI Docker image for Docksal

This image focuses on console tools necessary to develop LAMP stack (and other web) applications.

This image(s) is part of the Docksal image library.

Features

  • Based on the official php-fpm Debian 12 (bookworm) images
  • php/php-fpm (w/ xdebug), nodejs (via nvm), python, ruby
  • Framework specific tools for Drupal and Wordpress
  • Miscellaneous cli tools for day to day web development
  • Hosting provider cli tools (Acquia, Pantheon, Platform.sh)
  • Cron job scheduling
  • Custom startup script support
  • VS Code Server (VS Code in the browser)
  • Multi-platform images (amd64/arm64) starting with v3.0.0

Versions and image tag naming convention

  • Stable versions v3
    • php8.1-3.8, php8.1 - PHP 8.1
    • php8.2-3.8, php8.2 - PHP 8.2
    • php8.3-3.8, php8.3, latest - PHP 8.3
  • Development versions
    • php8.1-edge - PHP 8.1
    • php8.2-edge - PHP 8.2
    • php8.3-edge - PHP 8.3

PHP

  • php-fpm && php-cli
  • xdebug v3
  • composer v1 & v2
  • drush (Drupal)
    • coder-8.x + phpcs
  • drupal console launcher (Drupal)
  • wp-cli (Wordpress)

This image uses the official php-fpm images from Docker Hub as the base. This means that PHP and all modules are installed from source. Extra modules have to be installed in the same manner (installing them with apt-get won't work).

Available PHP database drivers

  • SQLite - via sqlite3, pdo_sqlite
  • MySQL - via mysqli, mysqlnd, pdo_mysql
  • PostgreSQL - via pgsql, pdo_pgsql
  • MSSQL - via sqlsrv and pdo_sqlsrv

Using PHP Xdebug

Xdebug is disabled by default.

To enable it, run the image with XDEBUG_ENABLED=1:

cli
...
  environment:
    ...
    - XDEBUG_ENABLED=1
    ...

See docs on using Xdebug for web and cli PHP debugging.

NodeJS

  • nvm
  • node v20.12.2 (following NodeJS LTS release cycle)
  • yarn (classic v1)

NodeJS is installed via nvm in the docker user's profile inside the image (/home/docker/.nvm).

If you need a different version of node, use nvm to install it, e.g., nvm install 21.7.3. Then, use nvm use 21.7.3 to use it in the current session or nvm alias default 21.7.3 to use it by default.

Python

This image comes with a system level installed Python v3.9.x from upstream Debian 11.

Ruby

This image comes with a system level installed Ruby v2.7.x from upstream Debian 11.

Notable console tools

  • git with git-lfs
  • curl, wget
  • zip, unzip
  • jq, yq
  • mysql, pgsql, and sqlsrv cli clients
  • imagemagick, ghostscript
  • mc, nano, rsync
  • cron

Hosting provider tools

Also, see the Secrets section below for more information on managing and using your hosting provider keys.

Customizing startup

To run a custom startup script anytime the cli container has started, create a startup.sh file within the .docksal/services/cli directory. Additionally, make sure that the file is executable as well so that the container does not run into issues when attempting to execute the file.

Scheduling cron jobs

Cron can be configured by making sure there is a crontab file located within .docksal/services/cli. The file should follow the standard crontab format.

Secrets and integrations

cli can read secrets from environment variables and configure the respective integrations automatically at start.

The recommended place store secrets in Docksal is the global $HOME/.docksal/docksal.env file on the host. From there, secrets are injected into the cli container's environment.

Below is the list of secrets currently supported.

SECRET_SSH_PRIVATE_KEY

Use to pass a private SSH key. The key will be stored in /home/docker/.ssh/id_rsa inside cli and will be considered by the SSH client in addition to the keys loaded in docksal-ssh-agent when establishing a SSH connection from within cli.

This is useful when you need a project stack to inherit a private SSH key that is not shared with other project stacks on the same host (e.g., in shared CI environments).

The value must be base64 encoded, i.e.:

cat /path/to/some_key_rsa | base64

SECRET_ACQUIA_CLI_KEY and SECRET_ACQUIA_CLI_SECRET

Credentials used to authenticate Acquia CLI with Acquia Cloud APIv2. Stored as ACQUIA_CLI_KEY and ACQUIA_CLI_SECRET environment variables inside cli.

Acquia CLI is installed and available globally in cli as acli.

SECRET_TERMINUS_TOKEN

Credentials used to authenticate Terminus with Pantheon. Stored in /home/docker/.terminus/ inside cli.

Terminus is installed and available globally in cli as terminus.

SECRET_PLATFORMSH_CLI_TOKEN

Credentials used to authenticate with the Platform.sh CLI tool. Stored in /home/docker/.platform inside cli.

Platform CLI is installed and available globally in cli as platform.

WEB_KEEPALIVE

Sets the delay in seconds between pings of the web container during execution fin exec. Setting this variable to non zero value prevents the project from stopping in cases of long fin exec and web container inactivity. Disabled by default (set to 0).

Git configuration

When working with git from within the image, it will ask for the user.email and user.name set before you can commit. These can be passed as environment variables and will be applied at the container startup.

GIT_USER_EMAIL="[email protected]"
GIT_USER_NAME="Docksal CLI"

Coder (Visual Studio Code web IDE)

Coder is a free, open-source web IDE.

VS Code Server is pre-installed along with GitLens and PHP Xdebug extensions.

Configuration

IDE_ENABLED (default: 0)

Set to 1 to start the image in IDE mode. VS Code web UI will is listening on port 8080.

IDE_PASSWORD (default: '')

Store your preferred password in this variable if you need to password protect the IDE environment.

See docs for instructions on using Coder in Docksal.

Composer

Composer v1 and v2 are both installed in the container. v2 is set as the default version, but while not all projects may be able to work with v2 quite yet, v1 is available by setting the COMPOSER_DEFAULT_VERSION variable to 1.

Example:

services:
  cli:
    environment:
      - COMPOSER_DEFAULT_VERSION=1

The following Composer optimization packages are no longer relevant/compatible with Composer v2 and have been dropped:

To benefit from these optimizations with Composer v1, you would need to pin the image to an older version. See Docksal documentation for more details.

service-cli's People

Contributors

achekulaev avatar apugacescu avatar asgorobets avatar boegie avatar cindytwilliams avatar damonsharp avatar fjmk avatar halison-imagex avatar jeroennoten avatar jhedstrom avatar lmakarov avatar lpeabody avatar marvil07 avatar mf-lit avatar nebel54 avatar sean-e-dietrich avatar sergey-zabolotny avatar shahinam avatar shelane avatar spurlos avatar tsdevelopment avatar willjackson avatar zrhoffman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

service-cli's Issues

How to add additional php modules?

I'm new to docker and docksal so maybe there is a very simple answer I didn't find yet:

Is there a way to configure additional php modules? For example I'm adding a redis container to my setup and would need php7.0-redis to be installied in the cli container. How would I do that?

Integration with Lastpass CLI

I would like to see Lastpass CLI integrated in service-cli container or even better - in separate standalone container independent from project.

https://github.com/lastpass/lastpass-cli

And ideally lastpass default config should be the following:

# let LPass passwords be read from standard input.
LPASS_DISABLE_PINENTRY=1
# Keep user signed in in LPass cli while container is running.
LPASS_AGENT_TIMEOUT=0

Examples:

Dockerfile (PHP 7.1)

FROM docksal/cli:2.2-php7.1
RUN apt-get update && apt-get -y --no-install-recommends install openssl \
    libcurl4-openssl-dev libxml2 libssl1.0-dev libxml2-dev pinentry-curses xclip \
    cmake build-essential pkg-config gcc libyaml-dev; \
    printf "\n" | pecl install yaml-2.0.2; \
    docker-php-ext-enable yaml; \
    rm lastpass-cli-1.3.1/ -rf; \
    wget -qO- https://github.com/lastpass/lastpass-cli/archive/v1.3.1.tar.gz | tar zxf -; \
    cd lastpass-cli-1.3.1; \
    make; \
    make install; \
    cd ..;\
    rm lastpass-cli-1.3.1/ -rf; \
    apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Dockerfile (PHP 5.6)

FROM docksal/cli:1.3-php5
# Install Necessary libs.
RUN apt-get update; \
    apt-get -y --no-install-recommends install \
    libcurl4-openssl-dev \
    libxml2 \
    libssl-dev \
    libxml2-dev \
    pinentry-curses \
    xclip \
    cmake \
    pkg-config \
    php5-dev \
    libyaml-dev; \
    printf "\n" | pecl install yaml-1.3.1; \
    echo 'extension=yaml.so' | tee -a /etc/php5/mods-available/yaml.ini > /dev/null; \
    php5enmod yaml; \
    rm lastpass-cli-1.3.1/ -rf; \
    wget -qO- https://github.com/lastpass/lastpass-cli/archive/v1.3.1.tar.gz | tar zxf -; \
    cd lastpass-cli-1.3.1; \
    make; \
    make install; \
    cd ..;\
    rm lastpass-cli-1.3.1/ -rf; \
    apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Detailed instructions: https://github.com/lastpass/lastpass-cli#debianubuntu

Add PHP 7.3 support

Since PHP 7.3.0 is now released, an image with support for PHP 7.3 should now also be built.

How to install forever for node.js

Hello,

Thank you for a great product.

Usually, I install the subj. so:

  $ [sudo] npm install forever -g

I did it inside the cli container.
But it does not see forever:

docker@cli:/var/www$ forever
bash: forever: command not found

Update software versions

  • Composer v1.4.2
  • Drush v8.1.11
  • Drupal Console Launcher v1.0.0-rc20
  • Magento CodeGen v1.6.4
  • nvm v0.33.2
  • nodejs v6.10.3

Cann't override php.ini in 7.1

I am using the docksal/cli:edge-php7.1 image, which set default max_memory = 256MB for FPM. According to the docksal documentation, i should be able to override setting by placing a php.ini file in .docksal/etc/php/php.ini; this is not working anymore, even after i run 'fin reset'.

Include bcmath Drupal Commerce dependency ?

Drupal commerce for D8 has a dependency on bcmath. I was able to resolve with:

sudo apt-get update
sudo apt-get install php7.0-bcmath

Can we get bcmath included in the Dockerfile?

Create 1.x, 2.x tags

Using latest image is not always the best way to go, since an image can have a major version update with incompatible changes.

But using static tag (1.3, 2.2...) is not the best way either, since configuration goes stale over time and then people who pick up an old project will have to refresh it to even start an old project on the new version of fin.

Using 1.x or 2.x tags, what should point to the latest minor version of the 1.x, 2.x etc. branch, would make more sense, since it is unlikely to break compatibility with your automation and configuration, but at the same time will keep one updated to the latest version of the image which will have the highest chances of being compatible with the latest Docksal.

Add Drush Launcher to the project to better support site installed Drush 9

Currently one must be in the Drupal Webroot to use Drush. With projects moving to Drush 9 which is only supported installed per project adding the Drush Launcher makes sense.

Adding the Drush Launcher would allow running drush commands anywhere in a composer managed project and would automatically use the version of Drush installed in the project.

To allow Drush Launcher to fallback for projects that do not have Drush as part of the project (Drupal 7) the environmental variable DRUSH_LAUNCHER_FALLBACK should be set to the path to the globally installed Drush 8. The path to the Drush Launcher should be added to the $PATH so that it comes before any other drush command files.

See the command in this Drush Launcher issue for a command that will install the most recent version without having to update it each time a new version comes out.

Add nvm back

Originally reported in docksal/docksal#587

In the edge versions on docksal/cli nvm was removed and replaces with a global nodejs installation.
We should add nvm back, but without the default node version. This way, if someone needs a non-default (global) nodejs version, they can install it with nvm.

PHP 7.1 and 7.2 images

Please create PHP 7.1 and 7.2 images. Some Drupal 8 projects requires at least 7.1.

Thank you

Best regards

nvm does not work in `fin bash`

image: docksal/cli:2.4-php7.1

17:27:53 ~/Projects/test
§ fin exec nvm --version
0.33.11

17:28:00 ~/Projects/test
§ fin bash
docker@cli:/var/www$ nvm --version
bash: nvm: command not found
docker@cli:/var/www$ 

Have master and release tag images match

With the current build/release process release tags are built separately (when a tag is published) from the master branch.

docksal/cli:<image-version>-php<php-version> != docksal/cli:php<php-version>

They should match.

This can be achieved by building tags from the latest stable versions instead if from scratch:

FROM docksal/cli:php<php-version>

Deprecate PHP 5.6 and 7.0

PHP 5.6 and 7.0 are EOL (end-of-life) as of now.

image

We will deprecate them in the upcoming docksal/cli release (v2.6.0) and drop support entirely in the next version (v2.7.0).

How to add php_soap extension for edge-php7.2

I am looking for a way to add an extension for edge-php7.2. Not sure if there's a way to do it via the etc/php/php-fpm.conf file.

If that is not doable, is that mean i have to create a new image with the extension for now? I am thinking there may be a way to dynamically add extension in the current image.

Thanks.

Empty SECRET_SSH_PRIVATE_KEY generates an empty id_rsa file

Empty SECRET_SSH_PRIVATE_KEY generates an empty id_rsa file and is causing issues with SSH authentication, I assume id_rsa is first key SSH will try to use, see command below for proof.

I believe the issue is present since 2.1 version of Docksal when this private key variable was introduced

Empty key:

fin exec cat /home/docker/.ssh/id_rsa                                                                                                                                                                  

Trying to SSH somewhere will try to use that key and ask for a passphrase (not sure why):

fin exec ssh -vvv example.com
.............
debug1: Trying private key: /home/docker/.ssh/id_rsa
Enter passphrase for key '/home/docker/.ssh/id_rsa':

Customize port for web IDE

Currently right now the port is hardcoded for 3000 allow for this to be customized with an environment.

Yarn executable not found in v2.3.0 en v2.4.0

Yarn was present and could be started directly in v2.2.0

$ docker run -t -i --rm docksal/cli:2.2-php7.1 /bin/bash
docker@c9f1773a7687:/var/www$ yarn -v
1.7.0

docker@c9f1773a7687:/var/www$ which yarn
/usr/bin/yarn

But in 2.3.0 and 2.4.0 it is missing.

$ docker run -t -i --rm docksal/cli:2.3-php7.1 /bin/bash
docker@1903e2648ff0:/var/www$ yarn -v
bash: yarn: command not found
$ docker run -t -i --rm docksal/cli:2.4-php7.1 /bin/bash
docker@3fedf4f59cf5:/var/www$ yarn
bash: yarn: command not found

I think I found the problem. v2.2.0 installed yarn using a package (as described on yarnpkg.com) by adding a repository and installing the yarn package. Starting from v2.3.0, yarn in installed using the install.sh script downloaded from yarnpkg.com. This results in yarn being installed in a other location:

Version location of yarn
2.2.0 /usr/bin/yarn
>= 2.3.0 /home/docker/.yarn/bin/yarn

Since /home/docker/.yarn/bin/ is missing from the $PATH variable, the yarn executable could not be found.

After adding it the the $PATH variable I got this message:

docker@cli:/var/www$ yarn
Yarn requires Node.js 4.0 or higher to be installed.

Yarn cannot find the node.js version installed in in /home/docker/.nvm/versions/node/. After adding /home/docker/.nvm/versions/node/v8.11.3/bin to $PATH, yarn could be executed.

docker@cli:/var/www$ yarn -v
1.8.0

Edit: The commit where the change from package to install script was made is 82a8258

Add PHP GMP Extention

Hi,

I am sure someone has done this before.

How would I add php7.1-gmp extention to cli ?

I tried searching using apt-cache searc php-gmp but nothing came up.

Regards,
Amjad

Sometimes npm complains about /home/docker/.config

I'm not sure why it happens but sometimes after fin rm and fun up cli gets created in a weird manner and npm complains about that file. (docksal/cli:1.2-php7)

Creating this issue to track this behavior and possible issue. Output is below. You might notice that owner of some files is not docker but 501. Which is weird, because docker user should have had id equal to 501 after "Changing uid/gid in cli to 501/20 to match the host". But it did not. That explains the nature of the error, but does not explain how did we get here.

08:34:35 Alexei-Workstation /Users/alexei.chekulaev/Projects/demo
$ fin rm -f
Removing containers...
Stopping demo_web_1 ... done
Stopping demo_cli_1 ... done
Stopping demo_mail_1 ... done
Stopping demo_db_1 ... done
Removing demo_web_1 ... done
Removing demo_cli_1 ... done
Removing demo_mail_1 ... done
Removing demo_db_1 ... done
Removing network demo_default
Removing volume demo_project_root
Volume docksal_ssh_agent is external, skipping
Removing volume demo_host_home

08:35:05 Alexei-Workstation /Users/alexei.chekulaev/Projects/demo
$ fin up
Starting services...
Creating network "demo_default" with the default driver
Creating volume "demo_project_root" with local driver
Creating volume "demo_host_home" with local driver
Creating demo_mail_1
Creating demo_cli_1
Creating demo_db_1
Creating demo_web_1
Changing uid/gid in cli to 501/20 to match the host
Resetting permissions on /var/www...
chown: changing ownership of ‘/var/www/node_modules/.bin/esparse’: Input/output error
chown: changing ownership of ‘/var/www/node_modules/.bin/esvalidate’: Input/output error
chown: changing ownership of ‘/var/www/node_modules/.bin/js-yaml’: Input/output error
chown: changing ownership of ‘/var/www/vendor/bin/php-parse’: Input/output error
chown: changing ownership of ‘/var/www/vendor/bin/psysh’: Input/output error
chown: changing ownership of ‘/var/www/vendor/bin/robo’: Input/output error
chown: changing ownership of ‘/var/www/vendor/bin/terminus’: Input/output error
Restarting php daemon...
Connected vhost-proxy to "demo_default" network.

08:35:26 Alexei-Workstation /Users/alexei.chekulaev/Projects/demo
$ fin run ls -la /home/docker

┌──────────────────────────────────────────────────────────┐
│                 npm update check failed                  │
│           Try running with sudo or get access            │
│           to the local update config store via           │
│ sudo chown -R $USER:$(id -gn $USER) /home/docker/.config │
└──────────────────────────────────────────────────────────┘
total 64
drwxr-xr-x  24    501  100 4096 May  4 12:35 .
drwxr-xr-x  12 root   root 4096 May  4 12:35 ..
drwxr-xr-x   2 docker  100 4096 May  4 12:35 .acquia
-rw-r--r--   1 docker  100  140 Apr  7 17:41 .bash_aliases
-rw-r--r--   1    501  100  220 Nov  5 21:22 .bash_logout
-rw-r--r--   1    501  100 3618 Apr  7 17:39 .bashrc
drwxr-xr-x   6 docker  100 4096 May  4 12:35 .composer
-rw-r--r--   1 docker  100  377 Apr  7 17:29 .docksalrc
drwxr-xr-x   7 docker  100 4096 May  4 12:35 .drush
drwxr-xr-x 340 docker  100 4096 May  4 12:35 .npm
drwxr-xr-x  14    501  100 4096 May  4 12:35 .nvm
-rw-r--r--   1 docker  100  716 Apr  7 17:41 .profile
drwxr-xr-x   2 docker  100 4096 May  4 12:35 .ssh
lrwxrwxrwx   1    501  100   36 Apr  7 17:38 .zlogin -> /home/docker/.zprezto/runcoms/zlogin
lrwxrwxrwx   1    501  100   37 Apr  7 17:38 .zlogout -> /home/docker/.zprezto/runcoms/zlogout
drwxr-xr-x  10 docker  100 4096 May  4 12:35 .zprezto
lrwxrwxrwx   1    501  100   39 Apr  7 17:38 .zpreztorc -> /home/docker/.zprezto/runcoms/zpreztorc
lrwxrwxrwx   1    501  100   38 Apr  7 17:38 .zprofile -> /home/docker/.zprezto/runcoms/zprofile
lrwxrwxrwx   1    501  100   36 Apr  7 17:38 .zshenv -> /home/docker/.zprezto/runcoms/zshenv
lrwxrwxrwx   1    501  100   35 Apr  7 17:38 .zshrc -> /home/docker/.zprezto/runcoms/zshrc
drwxr-xr-x   4 docker  100 4096 May  4 12:35 drush6
drwxr-xr-x   4 docker  100 4096 May  4 12:35 drush7

Notice: no .config dir at all!


After I got to this situation I got confused, so I did fin rm and fin up once again. And it just went back to normal.

08:37:03 Alexei-Workstation /Users/alexei.chekulaev/Projects/demo
$ fin rm 
WARNING: All containers and volumes for the current project will be removed!
Continue? [y/n]: y
Removing containers...
Stopping demo_web_1 ... done
Stopping demo_db_1 ... done
Stopping demo_cli_1 ... done
Stopping demo_mail_1 ... done
Removing demo_web_1 ... done
Removing demo_db_1 ... done
Removing demo_cli_1 ... done
Removing demo_mail_1 ... done
Removing network demo_default
Removing volume demo_project_root
Volume docksal_ssh_agent is external, skipping
Removing volume demo_host_home

08:37:23 Alexei-Workstation /Users/alexei.chekulaev/Projects/demo
$ fin up
Starting services...
Creating network "demo_default" with the default driver
Creating volume "demo_project_root" with local driver
Creating volume "demo_host_home" with local driver
Creating demo_cli_1
Creating demo_mail_1
Creating demo_db_1
Creating demo_web_1
Changing uid/gid in cli to 501/20 to match the host
Resetting permissions on /var/www...
chown: changing ownership of ‘/var/www/node_modules/.bin/esparse’: Input/output error
chown: changing ownership of ‘/var/www/node_modules/.bin/esvalidate’: Input/output error
chown: changing ownership of ‘/var/www/node_modules/.bin/js-yaml’: Input/output error
chown: changing ownership of ‘/var/www/vendor/bin/php-parse’: Input/output error
chown: changing ownership of ‘/var/www/vendor/bin/psysh’: Input/output error
chown: changing ownership of ‘/var/www/vendor/bin/robo’: Input/output error
chown: changing ownership of ‘/var/www/vendor/bin/terminus’: Input/output error
Restarting php daemon...
Connected vhost-proxy to "demo_default" network.

08:37:45 Alexei-Workstation /Users/alexei.chekulaev/Projects/demo
$ fin exec ls
222  app.js  composer.json  composer.lock  docker-compose.yml  docroot  installer.phar  node_modules  vendor

Add rvm support

Make it possible to install additional Ruby versions and switch between them via rvm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.