Skip to content

Commit

Permalink
Added Docker setup (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
vidarl authored and pjcdawkins committed Nov 26, 2019
1 parent e1e24b3 commit 38110a7
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .env-dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
USER_ID=1000
GROUP_ID=1000

SSH_KEY=id_rsa

#COMPOSE_PROJECT_NAME=psh-cli

35 changes: 35 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,38 @@ Run tests with:
```

Tests are also run on Travis CI: https://travis-ci.org/platformsh/platformsh-cli

## Developing in a docker container

If you don't have PHP installed locally or for other reasons want to do development on the
Platform.sh CLI inside a docker container, follow this procedure:

Create a `.env` file based on the default one

```sh
cp .env-dist .env
```

You should ensure that the UID and GUI used inside the container matches your local user to avoid file permission problems.
To get the UID and GID for local user, run:

```sh
id
```

If your `uid` and and `gid` is not `1000`, then alter `USER_ID` and `GROUP_ID` in `.env` accordingly.


Next, build and start your container

```sh
docker-compose up -d
```

Attach to the running container

```sh
docker-compose exec cli bash
```

Now you may run the steps mentioned in ["Developing locally"](#Developing-locally) inside the container.
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM php:7.3-cli

ARG USER_ID
ARG GROUP_ID

RUN apt-get update -q -y && apt-get install -y \
wget \
openssh-client \
git \
unzip \
&& docker-php-ext-install -j$(nproc) pcntl \
&& rm -rf /var/lib/apt/lists/*

RUN groupadd --gid ${GROUP_ID:-1000} psh; adduser --uid ${USER_ID:-1000} --gid ${GROUP_ID:-1000} --disabled-password --gecos "" psh

ADD docker/install_composer.sh /install_composer.sh
RUN /install_composer.sh; rm /install_composer.sh

USER psh

RUN mkdir /home/psh/.ssh

WORKDIR /home/psh/platformsh-cli
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.3'
# Simple setup for dev

services:
cli:
build:
context: .
dockerfile: Dockerfile
args:
USER_ID: ${USER_ID:-1000}
GROUP_ID: ${GROUP_ID:-1000}
volumes:
- .:/home/psh/platformsh-cli:cached
- $HOME/.ssh/${SSH_KEY}:/home/psh/.ssh/${SSH_KEY}
- $HOME/.platformsh:/home/psh/.platformsh
stdin_open: true
tty: true
network_mode: bridge
20 changes: 20 additions & 0 deletions docker/install_composer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
# Based on https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md

set -e

EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"

if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
exit 1
fi

php composer-setup.php --quiet
rm composer-setup.php

mv composer.phar /usr/bin/composer

0 comments on commit 38110a7

Please sign in to comment.