-
Notifications
You must be signed in to change notification settings - Fork 5
added new version of Dockerfile and convenience script #2
base: master
Are you sure you want to change the base?
Changes from all commits
06c5581
a6a8531
65a1254
668f3d3
8051f6b
e1813c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,26 +1,35 @@ | ||||||||||||||
| FROM php:7.4 | ||||||||||||||
|
|
||||||||||||||
| # Install npm | ||||||||||||||
| # libzip-dev: for the PHP zip extension (used by Composer) | ||||||||||||||
| RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - \ | ||||||||||||||
| && apt update && apt install -y git ssh apache2-utils nodejs python3-pip libzip-dev zip && rm -rf /var/lib/apt/lists/* | ||||||||||||||
|
|
||||||||||||||
| # Install Composer | ||||||||||||||
| RUN curl -sS https://getcomposer.org/installer | php \ | ||||||||||||||
| && mv composer.phar /usr/local/bin/composer \ | ||||||||||||||
| && chmod +x /usr/local/bin/composer | ||||||||||||||
|
|
||||||||||||||
| # Install the `aws` CLI tool | ||||||||||||||
| RUN pip3 install --upgrade --user awscli && echo 'export PATH=/root/.local/bin:$PATH'>/root/.bashrc | ||||||||||||||
|
|
||||||||||||||
| # Install serverless | ||||||||||||||
| RUN npm install -g serverless | ||||||||||||||
|
|
||||||||||||||
| RUN docker-php-ext-install zip pdo_mysql | ||||||||||||||
|
|
||||||||||||||
| RUN mkdir -p /var/task | ||||||||||||||
|
|
||||||||||||||
| # Register the Serverless and AWS bin directories | ||||||||||||||
| ENV PATH="/root/.serverless/bin:/root/.local/bin:${PATH}" | ||||||||||||||
|
|
||||||||||||||
| WORKDIR '/var/task' | ||||||||||||||
| FROM composer:latest | ||||||||||||||
|
|
||||||||||||||
| # composer | ||||||||||||||
| # https://github.com/composer/docker/blob/master/1.10/Dockerfile | ||||||||||||||
| # based on php:7-alpine | ||||||||||||||
| # https://github.com/docker-library/php/blob/master/7.4/alpine3.11/cli/Dockerfile | ||||||||||||||
| # based on alpine:3.11 | ||||||||||||||
|
|
||||||||||||||
| # Package Dependencies: | ||||||||||||||
| # serverless | ||||||||||||||
| # docker | ||||||||||||||
| # awscli | ||||||||||||||
| # groff: needed by the AWS cli | ||||||||||||||
| # hirak/prestissimo: accelerates installing Composer dependencies | ||||||||||||||
| # yarn: npm alternative | ||||||||||||||
| RUN adduser -D -G users -h /home/app app \ | ||||||||||||||
| && composer global require hirak/prestissimo \ | ||||||||||||||
|
mnapoli marked this conversation as resolved.
|
||||||||||||||
| && apk add --no-cache \ | ||||||||||||||
| docker \ | ||||||||||||||
| yarn \ | ||||||||||||||
| groff \ | ||||||||||||||
| && yarn global add serverless \ | ||||||||||||||
| && pip3 install \ | ||||||||||||||
| --progress-bar off \ | ||||||||||||||
| --no-cache-dir \ | ||||||||||||||
| --disable-pip-version-check \ | ||||||||||||||
| awscli | ||||||||||||||
|
|
||||||||||||||
| USER app | ||||||||||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned above, I'm not sure if this is necessary, but it works.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the bit I'm cautious about. If we can do without that would be great, the last thing I would want is debugging these kind of issues 😄
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| ENV PATH=$PATH:/tmp/vendor/bin \ | ||||||||||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure which packages you have in mind? Do you have an example of a use case?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this might be for Prestissimo to work. |
||||||||||||||
| COMPOSER_HOME=/var/task/.composer | ||||||||||||||
| VOLUME /var/task | ||||||||||||||
| VOLUME /home/app/.aws | ||||||||||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The location to AWS settings directory. Located under created user, but it also "might" work under
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
| VOLUME /var/run/docker.sock | ||||||||||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docker socket file location necessary for successfully working Docker in Docker.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| WORKDIR /var/task | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,22 @@ | ||
| This repository provides a development environment for Bref via a Docker image. | ||
| This repository provides a development environment for Bref via single Docker image and convenience script. | ||
|
mnapoli marked this conversation as resolved.
|
||
|
|
||
| Thanks to that image you can easily get started with Bref without having to install its tools: `serverless`, `aws`, `php`, `composer`… | ||
|
|
||
| ## Usage | ||
|
|
||
| Run any command in the container: | ||
| Run any command in the container using `./dev-env`: | ||
|
|
||
| ```bash | ||
| docker run --rm -it bref/dev-env <command> | ||
| ./dev-env <command> | ||
|
|
||
| # For example: | ||
| docker run --rm -it bref/dev-env php -v | ||
| ./dev-env php -v | ||
| ``` | ||
|
|
||
| You can also clone this repo and make a symlink of `dev-env` script to somewhere in your `$PATH`. | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a mention on other way to download this script (e.g. from Bref Doc), once we decide which/how. |
||
|
|
||
| ## Explanations | ||
|
|
||
| Bref is NOT preinstalled in `bref/dev-env` image. For it to work you have to first install it via `./dev-env composer require bref/bref`. This will create not only typical `vendor` directory in your project but also `.composer` directory for Composer cache, which you can add to your `.gitignore` file. | ||
|
|
||
| The Serverless util uses `.serverless` directory also located in your project. You can ignore that as well. | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||||
| #!/usr/bin/env bash | ||||||||
|
mnapoli marked this conversation as resolved.
|
||||||||
|
|
||||||||
| set -eu | ||||||||
|
mnapoli marked this conversation as resolved.
|
||||||||
|
|
||||||||
| # This is an array of where the Docker socket usually is on most distributions | ||||||||
| declare -a POSSIBLE_DOCKER_SOCK_PATHS=( | ||||||||
|
meridius marked this conversation as resolved.
|
||||||||
| /run/docker.sock | ||||||||
| /var/run/docker.sock | ||||||||
|
meridius marked this conversation as resolved.
|
||||||||
| ) | ||||||||
|
|
||||||||
| # Path to your `docker.sock` file is required for `serverless invoke local --docker -f myFunction` to work. | ||||||||
| DOCKER_SOCK_PATH= | ||||||||
|
meridius marked this conversation as resolved.
|
||||||||
| readonly DOCKER_GROUP_ID=$(getent group docker | cut -d: -f3) | ||||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need GID of a user able to run Docker, so we can pass it to the container. This is because docker commands run in container will still be run via Docker socket so user running this container needs to be able to work with it.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add it above the |
||||||||
| readonly AWS_CONF_DIR="${HOME}/.aws" | ||||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where I assume AWS configuration will be |
||||||||
|
|
||||||||
| # Find out which of the possible paths for Docker socket is valid | ||||||||
| for path in "${POSSIBLE_DOCKER_SOCK_PATHS[@]}" ; do | ||||||||
|
meridius marked this conversation as resolved.
|
||||||||
| if [[ -S "${path}" ]]; then | ||||||||
| DOCKER_SOCK_PATH="${path}" | ||||||||
| break | ||||||||
| fi | ||||||||
| done | ||||||||
|
mnapoli marked this conversation as resolved.
|
||||||||
|
|
||||||||
| if [[ -z "${DOCKER_SOCK_PATH}" ]]; then | ||||||||
| echo "Unable to locate Docker socket." | ||||||||
| echo "Please make sure Docker service is installed." | ||||||||
| exit 1 | ||||||||
| fi | ||||||||
|
mnapoli marked this conversation as resolved.
|
||||||||
|
|
||||||||
| if [[ ! -d "${AWS_CONF_DIR}" ]]; then | ||||||||
| echo "AWS settings directory is not found in ${AWS_CONF_DIR}" | ||||||||
| exit 1 | ||||||||
| fi | ||||||||
|
mnapoli marked this conversation as resolved.
|
||||||||
|
|
||||||||
| # --user So that all files created in container are actually owned by the user running this container | ||||||||
| # --group-add Sets GID of a user able to run Docker since docker commands run in container | ||||||||
| # will still be run via Docker socket so user running this container needs to be able to work with it | ||||||||
| # The `HOST_AWS_CONF_DIR` ENV variable is needed for running `bref/dashboard`. | ||||||||
| # It's because we can't simply use volume mappings from inside of `bref/dev-env` container | ||||||||
| # since in case of Docker in Docker mappings are from host instead. | ||||||||
| docker run --rm --interactive --tty \ | ||||||||
|
meridius marked this conversation as resolved.
|
||||||||
| --user "$(id -u)":"$(id -g)" \ | ||||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. necessary so all files created in container are actually owned by the user running this container
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment breaks the multiline command, so I'd put the explanation under Explanations in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add it above the |
||||||||
| --group-add "${DOCKER_GROUP_ID}" \ | ||||||||
|
meridius marked this conversation as resolved.
|
||||||||
| --env HOST_AWS_CONF_DIR="${AWS_CONF_DIR}" \ | ||||||||
|
meridius marked this conversation as resolved.
|
||||||||
| --volume "${DOCKER_SOCK_PATH}:/var/run/docker.sock" \ | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment breaks the multiline command. In addition the explanation is already mentioned under Explanations in |
||||||||
| --volume "${AWS_CONF_DIR}:/home/app/.aws" \ | ||||||||
| --volume "${PWD}:/app" \ | ||||||||
|
mnapoli marked this conversation as resolved.
|
||||||||
| "bref/dev-env" "$@" | ||||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and final one - to pass all commands to the container
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||||
Uh oh!
There was an error while loading. Please reload this page.