Skip to content

Commit 26c251d

Browse files
committed
Rewrite Dockerfile and Circle for tagged builds
Our versioning is now based on git tags, rather than commit hashes on the `release` branch, and our Circle config and Docker setup both needed to be modified significantly to accomodate that.
1 parent 5e32488 commit 26c251d

File tree

4 files changed

+91
-32
lines changed

4 files changed

+91
-32
lines changed

.circleci/config.yml

+41-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 2
1+
version: 2.1
22
jobs:
33
build:
44
working_directory: ~/web-monitoring-diff
@@ -55,12 +55,12 @@ jobs:
5555
steps:
5656
- checkout
5757
- run: |
58-
docker build -t envirodgi/web-monitoring-diff:$CIRCLE_SHA1 .
58+
docker build -t envirodgi/web-monitoring-diff:${CIRCLE_SHA1} .
5959
- run:
6060
name: Save Image
6161
command: |
6262
mkdir /tmp/workspace
63-
docker save --output /tmp/workspace/docker-image envirodgi/web-monitoring-diff:$CIRCLE_SHA1
63+
docker save --output /tmp/workspace/docker-image envirodgi/web-monitoring-diff:${CIRCLE_SHA1}
6464
- persist_to_workspace:
6565
root: /tmp/workspace
6666
paths:
@@ -76,30 +76,50 @@ jobs:
7676
command: docker load --input /tmp/workspace/docker-image
7777
- run:
7878
name: Re-tag Image
79-
command: docker image tag envirodgi/web-monitoring-diff:$CIRCLE_SHA1 envirodgi/web-monitoring-diff:latest
79+
command: |
80+
if [ -n "${CIRCLE_TAG}" ]; then
81+
docker image tag envirodgi/web-monitoring-diff:${CIRCLE_SHA1} envirodgi/web-monitoring-diff:${CIRCLE_TAG:1}
82+
docker image tag envirodgi/web-monitoring-diff:${CIRCLE_SHA1} envirodgi/web-monitoring-diff:latest
83+
fi
8084
- run:
8185
name: Publish to Docker Hub
8286
command: |
8387
docker login -u $DOCKER_USER -p $DOCKER_PASS
84-
docker push envirodgi/web-monitoring-diff:$CIRCLE_SHA1
85-
docker push envirodgi/web-monitoring-diff:latest
88+
docker push envirodgi/web-monitoring-diff:${CIRCLE_SHA1}
89+
if [ -n "${CIRCLE_TAG}" ]; then
90+
docker push envirodgi/web-monitoring-diff:${CIRCLE_TAG:1}
91+
docker push envirodgi/web-monitoring-diff:latest
92+
fi
8693
8794
workflows:
88-
version: 2
8995
build:
9096
jobs:
91-
- build
92-
- build_docker
93-
# XXX: Temporarily disable while in the middle of extracting this package
94-
# For this repo, we should probably publish based on tags:
97+
# NOTE: because publishing runs on tags, we have to make sure all jobs
98+
# it depends on also run on tags (by default, jobs do not run on tags,
99+
# only branches).
100+
#
101+
# Also: {filters: {tags: {only: ...}}} may look deceiving, like it's only
102+
# running for the tags. But what's actually happening here is that
103+
# branches aren't being filtered (only tags are), so it's running for
104+
# *all* branches and also for tags that start with "v".
105+
#
106+
# See more in:
95107
# https://circleci.com/docs/2.0/workflows/#executing-workflows-for-a-git-tag
96-
# Use $CIRCLE_TAG to identify the tag being used:
97-
# https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables
98-
# - publish_docker:
99-
# requires:
100-
# - build
101-
# - build_docker
102-
# filters:
103-
# branches:
104-
# only:
105-
# - release
108+
- build:
109+
filters:
110+
tags:
111+
only: /^v.*/
112+
- build_docker:
113+
filters:
114+
tags:
115+
only: /^v.*/
116+
# Publishing only happens for tags starting with "v", and no branches.
117+
- publish_docker:
118+
requires:
119+
- build
120+
- build_docker
121+
filters:
122+
branches:
123+
ignore: /.*/
124+
tags:
125+
only: /^v.*/

.dockerignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
.env
2-
.git/
2+
3+
# DO NOT IGNORE .git!
4+
# We use Versioneer set package version information from git tags, so .git must
5+
# be available for it to work. We handle cleaning up the container for release
6+
# by having a multi-stage build, where the final container image only includes
7+
# the built package.
8+
# .git/

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ max_line_length = 79
99

1010
[*.rst]
1111
indent_size = 2
12+
13+
[*.{yaml,yml}]
14+
indent_size = 2

Dockerfile

+40-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
# Use an official Python runtime as a parent image
2-
FROM python:3.7-slim
1+
##
2+
# `base` contains the only the core system-level dependencies needed to run
3+
# the diff server. `dev` builds on it by adding compile-time support for the
4+
# same packages so that we can build the Python dependencies that have C code,
5+
# like `lxml`.
6+
# We separate them out so that the final `release` image can layer on top of
7+
# this one without needing compiler-related packages.
8+
##
9+
FROM python:3.7-slim as base
310
LABEL maintainer="[email protected]"
411

512
RUN apt-get update && apt-get install -y --no-install-recommends \
6-
git gcc g++ pkg-config libxml2-dev libxslt-dev libz-dev \
7-
libssl-dev openssl libcurl4-openssl-dev
13+
libxml2 libxslt1.1 libz1 openssl libcurl4
14+
15+
16+
##
17+
# `dev` is an intermediate image that is used for building compiled
18+
# dependencies or can be used as a development environment if you want to work
19+
# in a Docker container.
20+
##
21+
FROM base as dev
22+
23+
RUN apt-get update && apt-get install -y --no-install-recommends \
24+
git gcc g++ pkg-config \
25+
# Compiler-support for the system dependencies in `base`
26+
libxml2-dev libxslt-dev libz-dev libssl-dev libcurl4-openssl-dev
827

928
# Set the working directory to /app
1029
WORKDIR /app
1130

31+
RUN pip install --upgrade pip
1232
# Copy the requirements.txt alone into the container at /app
1333
# so that they can be cached more aggressively than the rest of the source.
1434
ADD requirements.txt /app
@@ -20,12 +40,22 @@ RUN pip install --trusted-host pypi.python.org -r requirements-experimental.txt
2040

2141
# Copy the rest of the source.
2242
ADD . /app
43+
# ...and install!
44+
RUN pip install .[server] --no-binary lxml
2345

24-
# Install package.
25-
RUN pip install .
2646

27-
# Make port 80 available to the world outside this container.
28-
EXPOSE 80
47+
##
48+
# `release` is the final, release-ready image with only the necessary
49+
# dependencies to run all diffs and the diff server.
50+
##
51+
FROM base as release
52+
53+
# Copy built python dependencies.
54+
COPY --from=dev /usr/local/lib/ /usr/local/lib/
55+
# Copy executables.
56+
COPY --from=dev /usr/local/bin /usr/local/bin
2957

30-
# Run server on port 80 when the container launches.
31-
CMD ["web-monitoring-diff-server", "80"]
58+
ENV LD_LIBRARY_PATH=/usr/local/lib
59+
60+
EXPOSE 80
61+
CMD ["web-monitoring-diff-server", "--port", "80"]

0 commit comments

Comments
 (0)