-
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 4 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,36 @@ | ||||||||||||||||||||||||||||||||||||||
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:1.10.4 | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
# composer:1.10.4 | ||||||||||||||||||||||||||||||||||||||
# 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 | ||||||||||||||||||||||||||||||||||||||
mnapoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
# hirak/prestissimo: accelerates installing Composer dependencies | ||||||||||||||||||||||||||||||||||||||
# yarn: npm alternative | ||||||||||||||||||||||||||||||||||||||
# groff: needed by the AWS cli | ||||||||||||||||||||||||||||||||||||||
RUN adduser -D -G users -h /home/app app \ | ||||||||||||||||||||||||||||||||||||||
meridius marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
&& composer global require hirak/prestissimo \ | ||||||||||||||||||||||||||||||||||||||
mnapoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
&& apk add --no-cache \ | ||||||||||||||||||||||||||||||||||||||
docker=19.03.5-r0 \ | ||||||||||||||||||||||||||||||||||||||
mnapoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
yarn=1.19.2-r0 \ | ||||||||||||||||||||||||||||||||||||||
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 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. All Bref docs mention npm, could we install it? (we can also have yarn, why not) 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. Well, the docs mention it exactly 3 times:
But I guess we can have |
||||||||||||||||||||||||||||||||||||||
groff=1.22.4-r0 \ | ||||||||||||||||||||||||||||||||||||||
mnapoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
&& yarn global add [email protected] \ | ||||||||||||||||||||||||||||||||||||||
mnapoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
&& pip3 install \ | ||||||||||||||||||||||||||||||||||||||
--progress-bar off \ | ||||||||||||||||||||||||||||||||||||||
--no-cache-dir \ | ||||||||||||||||||||||||||||||||||||||
--disable-pip-version-check \ | ||||||||||||||||||||||||||||||||||||||
awscli==1.18.39 | ||||||||||||||||||||||||||||||||||||||
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. Installing Original 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. 👍 thanks Could you add this information into a comment? 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
However I'm against explaining options since user should be able to read it easily from their names (that's why i don't use short variants, if at all possible) and if not they should read docs of given program where more information and related info could be. |
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
USER app | ||||||||||||||||||||||||||||||||||||||
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. 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 😄 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 \ | ||||||||||||||||||||||||||||||||||||||
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 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? 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 | ||||||||||||||||||||||||||||||||||||||
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 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 | ||||||||||||||||||||||||||||||||||||||
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. 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
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,26 @@ | ||
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.
Show resolved
Hide 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.sh`: | ||
|
||
```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 | ||
mnapoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
You can also clone this repo and make a symlink of `dev-env` script to somewhere in your `$PATH`. | ||
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 | ||
|
||
Path to your `docker.sock` file is required for `serverless invoke local --docker -f myFunction` to work. | ||
|
||
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. | ||
|
||
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. | ||
meridius marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||||
#!/usr/bin/env bash | ||||||||
mnapoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
||||||||
set -eu | ||||||||
mnapoli marked this conversation as resolved.
Show resolved
Hide 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.
Show resolved
Hide resolved
|
||||||||
/run/docker.sock | ||||||||
/var/run/docker.sock | ||||||||
meridius marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
) | ||||||||
DOCKER_SOCK_PATH= | ||||||||
meridius marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
readonly DOCKER_GROUP_ID=$(getent group docker | cut -d: -f3) | ||||||||
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. 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" | ||||||||
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.
Show resolved
Hide resolved
|
||||||||
if [[ -S "${path}" ]]; then | ||||||||
DOCKER_SOCK_PATH="${path}" | ||||||||
break | ||||||||
fi | ||||||||
done | ||||||||
mnapoli marked this conversation as resolved.
Show resolved
Hide 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.
Show resolved
Hide 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.
Show resolved
Hide resolved
|
||||||||
|
||||||||
docker run --rm --interactive --tty \ | ||||||||
meridius marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
--user "$(id -u)":"$(id -g)" \ | ||||||||
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 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
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 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.
Show resolved
Hide resolved
|
||||||||
--env HOST_AWS_CONF_DIR="${AWS_CONF_DIR}" \ | ||||||||
meridius marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
--volume "${DOCKER_SOCK_PATH}:/var/run/docker.sock" \ | ||||||||
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
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.
Show resolved
Hide resolved
|
||||||||
"bref/dev-env" "$@" | ||||||||
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 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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the start I chose to use Alpine-based image for the following reasons:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, why not use the
latest
version?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment really necessary? I mean yes, it's smaller than something else, but we could pick many other facts. Should we state them too? And how would we know which ones?
And for the
latest
. You really shouldn't use it when you need to do something that depends on the system version. For example we know that Alpine 3.11 hasdocker=19.03.5-r0
in repository, but what will thelatest
a month from now have?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is to make my life, as maintainer, easier. In 1 year, I will stumble on that code and not remember why we chose that image over a classic linux distribution.
Good point.
So does that mean that I will have to regularly update the version here, and then update the Docker version below too? How can I find the Docker version for the Alpine version that is referenced here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the
latest
through again and I think we can use it in this situation eventually. The only things we might require specific versions of are onlyserverless
andawscli
, and maybe even those not. So if we leave out specifying package versions we can have the base system aslatest
.I'll push the changes.
BTW, you can find the available packages per Alpine release at https://pkgs.alpinelinux.org/packages?name=docker&branch=v3.11&arch=x86_64