Skip to content

Instantly share code, notes, and snippets.

@devdrops
Last active October 3, 2017 03:00
Show Gist options
  • Save devdrops/9330fc784595634ca76380fe9bc8d467 to your computer and use it in GitHub Desktop.
Save devdrops/9330fc784595634ca76380fe9bc8d467 to your computer and use it in GitHub Desktop.
DiffCS: proposal for Docker environment
FROM php:7.1-cli
ARG VCS_REF
ARG BUILD_DATE
ARG RELEASE_VERSION
LABEL authors="Davi Marcondes Moreira <[email protected]>, Marcelo Santos <[email protected]>" \
org.label-schema.name="Docker/DiffCS" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.build-date=$BUILD_DATE \
org.label-schema.vcs-url="" \
org.label-schema.schema-version="1.0"
RUN curl -LO https://github.com/marcelsud/diffcs/releases/download/$RELEASE_VERSION/diffcs.phar && \
chmod +x diffcs.phar && \
mv diffcs.phar /usr/local/bin/diffcs && \
curl -LO https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar && \
chmod +x phpcs.phar && \
mv phpcs.phar /usr/local/bin/phpcs
ENTRYPOINT ["diffcs"]
CMD ["--help"]

Instructions

I'm proposing some updates on the Docker image:

  • Usage of php:7.1-cli instead of the regular php:7. This change provides the official PHP image on Docker Hub, on it's currently latest tag. Also it only have the PHP CLI version, so the image is more clean (without the extra PHP settings required for the Web version).
  • Usage of arguments. This provides a powerful resource for Docker images as labels, provided by Microbadger, a service designed to inspect what's inside Docker images, along with extra data like image name, VCS reference by latest commit, build date and VCS URL.
  • Put all commands into a single RUN declaration. This makes the image lightier than it was before, as for each RUN it creates a new layer (the more the more layers, the heavier the image gets).

How to build this image?

Go to the terminal and run:

docker build -t marcelsud/diffcs:v0.2.1 \
  --build-arg VCS_REF=`git rev-parse --short HEAD` \
  --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
  --build-arg RELEASE_VERSION='v0.2.1' \
  . 

The build arguments, as described below:

  • VCS_REF indicates the last commit, shortened. Useful for GitHub integrations.
  • BUILD_DATE indicates the date when the image was built.
  • RELEASE_VERSION indicates which DiffCS version should be installed. So you don't have to edit your Dockerfile for each time you want to generate a new tag of it ๐Ÿ˜‰

Also, I strongly suggest to execute he build process twice, for each release:

  1. The first using the tag related to the project's current tag, as marcelsud/diffcs:v0.2.1;
  2. Then finally the last one, using the latest tag, as marcelsud/diffcs:latest, in order to always provide the top-fresh version on latest.

Then at last, publish each tag as below:

docker push marcelsud/diffcs:v0.2.1

OBS

  • Keep in mind that you can use the same arguments in the automated build process through Docker Hub! ๐Ÿ˜‰
  • Use the org.label-schema.vcs-url label if you want to keep your Dockerfile under GitHub.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment