Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker work-flow improvements #900

Merged
merged 9 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ Adjust these parameters by clicking the docker icon in the toolbar,
selecting preferences, and click the "Advanced" icon. Make sure to click
"Apply & Restart" so that the adjustments will go into effect.

Build and Deploy Docker Images
--------------------------------
- Build worker node images: `make dist-build -e TAG=$TAG`
- Build webapp image: `make webapp-build -e TAG=$TAG`
- Push worker node images: `make dist-push -e TAG=$TAG`
- Push webapp image: `make webapp-push -e TAG=$TAG -e VERSION=$VERSION`
- Release webapp image: `make webapp-release -e VERSION=$VERSION`

Note:
- `TAG` refers to the GitHub release version or local branch
- `VERSION` refers to the app type, either test (`test`) or production (`prod`)
- The OSPC token is not required if the PUF is not required

Other useful commands
-------------------------
- View logs
Expand Down
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
OSPC_ANACONDA_TOKEN := `cat ~/.ospc_anaconda_token`
NEW_RELIC_TOKEN := `cat ~/.newrelic-$(VERSION)`

dist-build:
cd distributed && \
docker build -t opensourcepolicycenter/distributed:$(TAG) ./ --build-arg PUF_TOKEN=$(OSPC_ANACONDA_TOKEN) && \
docker build --no-cache --build-arg TAG=$(TAG) -t opensourcepolicycenter/flask:$(TAG) --file Dockerfile.flask ./ && \
docker build --no-cache --build-arg TAG=$(TAG) -t opensourcepolicycenter/celery:$(TAG) --file Dockerfile.celery ./

dist-push:
cd distributed && \
docker push opensourcepolicycenter/distributed:$(TAG) && \
docker push opensourcepolicycenter/flask:$(TAG) && \
docker push opensourcepolicycenter/celery:$(TAG)

dist-test:
cd distributed && \
docker-compose rm -f && \
docker-compose run flask py.test -s -v && \
docker-compose rm -f

webapp-build:
docker build --build-arg NEW_RELIC_TOKEN=$(NEW_RELIC_TOKEN) -t opensourcepolicycenter/web:$(TAG) ./

webapp-push:
docker tag opensourcepolicycenter/web:$(TAG) registry.heroku.com/ospc-$(VERSION)/web
docker push registry.heroku.com/ospc-$(VERSION)/web
docker push opensourcepolicycenter/web:$(TAG)

webapp-release:
heroku container:release web -a ospc-$(VERSION)
3 changes: 1 addition & 2 deletions distributed/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM continuumio/miniconda

LABEL build="distributed" date="2018-06-13"
USER root
RUN apt-get update && apt install libgl1-mesa-glx --yes

Expand All @@ -19,7 +18,7 @@ RUN conda install python=2.7.14 numpy>=1.12.1 pandas>=0.23.0 taxcalc=0.20.1 \

RUN pip install -r requirements.txt

COPY . /home/distributed
RUN mkdir /home/distributed/taxbrain_server
WORKDIR /home/distributed/taxbrain_server

# not safe. don't publish with token
Expand Down
7 changes: 4 additions & 3 deletions distributed/Dockerfile.celery
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM opensourcepolicycenter/distributed:v1.6.0

LABEL build="celery" date="2018-06-13"
ARG TAG
FROM opensourcepolicycenter/distributed:$TAG

ENV CELERY_BROKER_URL redis://redis:6379/0
ENV CELERY_RESULT_BACKEND redis://redis:6379/0
ENV C_FORCE_ROOT true

COPY ./taxbrain_server /home/distributed/taxbrain_server

ENTRYPOINT celery -A celery_tasks worker --loglevel=info --concurrency=1
5 changes: 4 additions & 1 deletion distributed/Dockerfile.flask
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM opensourcepolicycenter/distributed:v1.6.0
ARG TAG
FROM opensourcepolicycenter/distributed:$TAG

LABEL build="flask" date="2018-06-13"

Expand All @@ -16,5 +17,7 @@ ENV DEBUG true
EXPOSE 80
EXPOSE 5050

COPY ./taxbrain_server /home/distributed/taxbrain_server

# run the app server
CMD ["gunicorn", "--bind", "0.0.0.0:5050", "flask_server:app"]
4 changes: 2 additions & 2 deletions distributed/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
version: '3'
services:
flask:
image: opensourcepolicycenter/flask:v1.6.0
image: "opensourcepolicycenter/flask:${TAG}"
ports:
- 5050:5050
depends_on:
- redis
celery:
image: opensourcepolicycenter/celery:v1.6.0
image: "opensourcepolicycenter/celery:${TAG}"
depends_on:
- redis
redis:
Expand Down
11 changes: 0 additions & 11 deletions distributed/docker_build.sh

This file was deleted.

9 changes: 9 additions & 0 deletions distributed/docker_retag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

docker tag opensourcepolicycenter/distributed:$OLDTAG opensourcepolicycenter/distributed:$NEWTAG
docker tag opensourcepolicycenter/flask:$OLDTAG opensourcepolicycenter/flask:$NEWTAG
docker tag opensourcepolicycenter/celery:$OLDTAG opensourcepolicycenter/celery:$NEWTAG

docker push opensourcepolicycenter/distributed:$NEWTAG
docker push opensourcepolicycenter/flask:$NEWTAG
docker push opensourcepolicycenter/celery:$NEWTAG