Skip to content

Commit b21f3a7

Browse files
author
Robert Chu
committed
Adds example dockerfile.
1 parent 4101468 commit b21f3a7

7 files changed

Lines changed: 312 additions & 22 deletions

File tree

.github/workflows/publish.yml

Lines changed: 179 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,63 @@ jobs:
1010
name: Publish script-runner to pypi
1111
runs-on: ubuntu-latest
1212
steps:
13-
- name: Publish a Python distribution to PyPI
13+
- name: Check out the repo
14+
uses: actions/checkout@v2
15+
- name: Prepare
16+
id: prep
17+
run: |
18+
PYTHON_IMAGE_TAG=alpine
19+
DOCKER_IMAGE=labflow/script-runner
20+
VERSION=latest
21+
if [[ $GITHUB_REF == refs/tags/* ]]; then
22+
VERSION=${GITHUB_REF#refs/tags/}
23+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
24+
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
25+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
26+
VERSION=pr-${{ github.event.number }}
27+
fi
28+
TAGS="${DOCKER_IMAGE}:${PYTHON_IMAGE_TAG}-latest,${DOCKER_IMAGE}:${PYTHON_IMAGE_TAG}-${VERSION}"
29+
if [ "${{ github.event_name }}" = "push" ]; then
30+
TAGS="$TAGS,${DOCKER_IMAGE}:${PYTHON_IMAGE_TAG}-sha-${GITHUB_SHA::8}"
31+
fi
32+
echo ::set-output name=version::${VERSION}
33+
echo ::set-output name=tags::${TAGS}
34+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
35+
echo ::set-output name=hashtag::"sha-${GITHUB_SHA::8}"
36+
echo ::set-output name=pyversion::"${PYTHON_IMAGE_TAG}"
37+
- name: Set up Python ${{ matrix.python-version }}
38+
uses: actions/setup-python@v2
39+
with:
40+
python-version: "3.8"
41+
- name: Install dependencies
42+
run: |
43+
python -m pip install --upgrade pip wheel setuptools pipenv
44+
# pipenv lock --dev --requirements > requirements.dev.txt
45+
# pip install -r requirements.txt
46+
# - name: Lint with flake8
47+
# run: |
48+
# # stop the build if there are Python syntax errors or undefined names
49+
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
50+
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
51+
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
52+
# - name: Test with pytest
53+
# run: |
54+
# pytest
55+
- name: Build python package
56+
run: |
57+
python setup.py sdist
58+
env:
59+
SCRIPT_RUNNER_VERSION: ${{ steps.prep.outputs.version }}
60+
- name: Deploy to PyPI
61+
if: success() && startsWith(github.ref, 'refs/tags')
1462
uses: pypa/gh-action-pypi-publish@release/v1
1563
with:
1664
user: __token__
1765
password: ${{ secrets.PYPI_API_TOKEN }}
1866

1967
publish-docker:
68+
needs: publish-pypi
69+
if: startsWith(github.ref, 'refs/tags')
2070
name: Publish script-runner to dockerhub
2171
runs-on: ubuntu-latest
2272
steps:
@@ -64,7 +114,7 @@ jobs:
64114
uses: docker/build-push-action@v2
65115
with:
66116
context: ./docker
67-
file: ./Dockerfile
117+
file: ./docker/Dockerfile
68118
builder: ${{ steps.buildx.outputs.name }}
69119
push: ${{ github.event_name != 'pull_request' }}
70120
tags: ${{ steps.prep.outputs.tags }}
@@ -78,10 +128,97 @@ jobs:
78128
SCRIPT_RUNNER_VERSION=${{ steps.prep.outputs.version }}
79129
PYTHON_IMAGE_TAG=${{ steps.prep.outputs.pyversion }}
80130
131+
publish-docker-example:
132+
needs: publish-pypi
133+
if: startsWith(github.ref, 'refs/tags')
134+
name: Build and push script-runner-server-example docker image
135+
runs-on: ubuntu-latest
136+
steps:
137+
- name: Check out the repo
138+
uses: actions/checkout@v2
139+
- name: Prepare
140+
id: prep
141+
run: |
142+
DOCKER_IMAGE=labflow/script-runner-example
143+
VERSION=edge
144+
if [[ $GITHUB_REF == refs/tags/* ]]; then
145+
VERSION=${GITHUB_REF#refs/tags/}
146+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
147+
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
148+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
149+
VERSION=pr-${{ github.event.number }}
150+
fi
151+
TAGS="${DOCKER_IMAGE}:latest,${DOCKER_IMAGE}:${VERSION}"
152+
if [ "${{ github.event_name }}" = "push" ]; then
153+
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
154+
fi
155+
echo ::set-output name=version::${VERSION}
156+
echo ::set-output name=tags::${TAGS}
157+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
158+
echo ::set-output name=hashtag::"sha-${GITHUB_SHA::8}"
159+
- name: Set up Docker Buildx
160+
id: buildx
161+
uses: docker/setup-buildx-action@v1
162+
- name: Cache Docker layers
163+
uses: actions/cache@v2.1.4
164+
with:
165+
path: /tmp/.buildx-cache
166+
key: ${{ runner.os }}-buildx-${{ github.sha }}
167+
restore-keys: |
168+
${{ runner.os }}-buildx-
169+
- name: Login to DockerHub
170+
if: github.event_name != 'pull_request'
171+
uses: docker/login-action@v1
172+
with:
173+
username: ${{ secrets.DOCKER_USERNAME }}
174+
password: ${{ secrets.DOCKER_PASSWORD }}
175+
- name: Push to Docker Hub
176+
uses: docker/build-push-action@v2
177+
with:
178+
context: ./docker
179+
file: ./docker/Dockerfile.example
180+
builder: ${{ steps.buildx.outputs.name }}
181+
push: ${{ github.event_name != 'pull_request' }}
182+
tags: ${{ steps.prep.outputs.tags }}
183+
cache-from: type=local,src=/tmp/.buildx-cache
184+
cache-to: type=local,dest=/tmp/.buildx-cache
185+
labels: |
186+
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
187+
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
188+
org.opencontainers.image.revision=${{ github.sha }}
189+
build-args: |
190+
SERVER_VERSION=${{ steps.prep.outputs.hashtag }}
191+
81192
deploy-aws-example:
193+
needs: publish-docker-example
194+
if: startsWith(github.ref, 'refs/tags')
82195
name: Deploy swabseq-analysis-example to AWS
83196
runs-on: ubuntu-latest
84197
steps:
198+
- name: Check out the repo
199+
uses: actions/checkout@v2
200+
201+
- name: Prepare
202+
id: prep
203+
run: |
204+
DOCKER_IMAGE=labflow/script-runner-example
205+
VERSION=edge
206+
if [[ $GITHUB_REF == refs/tags/* ]]; then
207+
VERSION=${GITHUB_REF#refs/tags/}
208+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
209+
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
210+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
211+
VERSION=pr-${{ github.event.number }}
212+
fi
213+
TAGS="${DOCKER_IMAGE}:latest,${DOCKER_IMAGE}:${VERSION}"
214+
if [ "${{ github.event_name }}" = "push" ]; then
215+
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
216+
fi
217+
echo ::set-output name=version::${VERSION}
218+
echo ::set-output name=tags::${TAGS}
219+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
220+
echo ::set-output name=hashtag::"sha-${GITHUB_SHA::8}"
221+
85222
- name: Configure AWS credentials
86223
uses: aws-actions/configure-aws-credentials@v1
87224
with:
@@ -92,28 +229,29 @@ jobs:
92229
- name: Setup Terraform tfvars
93230
uses: nowactions/envsubst@v1
94231
with:
95-
input: ./examples/aws/example.tfvars
96-
output: ./examples/aws/terraform.tfvars
232+
input: ./terraform/aws/example.tfvars
233+
output: ./terraform/aws/terraform.tfvars
97234
env:
98235
DNS_SUBDOMAIN: ${{secrets.DNS_SUBDOMAIN}}
99236
DNS_ZONE_ID: ${{secrets.DNS_ZONE_ID}}
237+
IMAGE_TAG: ${{steps.plan.outputs.hashtag}}
100238

101239
- name: Setup Terraform
102240
uses: hashicorp/setup-terraform@v1
103241

104242
# - name: Terraform Format
105243
# id: fmt
106-
# working-directory: ./examples/aws
244+
# working-directory: ./terraform/aws
107245
# run: terraform fmt -check
108246

109247
- name: Terraform Init
110248
id: init
111-
working-directory: ./examples/aws
249+
working-directory: ./terraform/aws
112250
run: terraform init
113251

114252
- name: Terraform Plan
115253
id: plan
116-
working-directory: ./examples/aws
254+
working-directory: ./terraform/aws
117255
if: github.event_name == 'pull_request'
118256
run: terraform plan -no-color
119257
continue-on-error: true
@@ -150,14 +288,40 @@ jobs:
150288
run: exit 1
151289

152290
- name: Terraform Apply
153-
working-directory: ./examples/aws
291+
working-directory: ./terraform/aws
154292
if: (github.event_name == 'release') || (github.event_name == 'push' && github.ref == 'refs/heads/main')
155293
run: terraform apply -auto-approve
156294

157295
deploy-azure-example:
296+
needs: publish-docker-example
297+
if: startsWith(github.ref, 'refs/tags')
158298
name: Deploy swabseq-analysis-example to Azure
159299
runs-on: ubuntu-latest
160300
steps:
301+
- name: Check out the repo
302+
uses: actions/checkout@v2
303+
304+
- name: Prepare
305+
id: prep
306+
run: |
307+
DOCKER_IMAGE=labflow/script-runner-example
308+
VERSION=edge
309+
if [[ $GITHUB_REF == refs/tags/* ]]; then
310+
VERSION=${GITHUB_REF#refs/tags/}
311+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
312+
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
313+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
314+
VERSION=pr-${{ github.event.number }}
315+
fi
316+
TAGS="${DOCKER_IMAGE}:latest,${DOCKER_IMAGE}:${VERSION}"
317+
if [ "${{ github.event_name }}" = "push" ]; then
318+
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
319+
fi
320+
echo ::set-output name=version::${VERSION}
321+
echo ::set-output name=tags::${TAGS}
322+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
323+
echo ::set-output name=hashtag::"sha-${GITHUB_SHA::8}"
324+
161325
- name: Configure Azure credentials
162326
uses: azure/login@v1
163327
with:
@@ -166,28 +330,29 @@ jobs:
166330
- name: Setup Terraform tfvars
167331
uses: nowactions/envsubst@v1
168332
with:
169-
input: ./examples/azure/example.tfvars
170-
output: ./examples/azure/terraform.tfvars
333+
input: ./terraform/azure/example.tfvars
334+
output: ./terraform/azure/terraform.tfvars
171335
env:
172336
DNS_SUBDOMAIN: ${{secrets.DNS_SUBDOMAIN}}
173337
DNS_ZONE_NAME: ${{secrets.DNS_ZONE_NAME}}
338+
IMAGE_TAG: ${{steps.plan.outputs.hashtag}}
174339

175340
- name: Setup Terraform
176341
uses: hashicorp/setup-terraform@v1
177342

178343
# - name: Terraform Format
179344
# id: fmt
180-
# working-directory: ./examples/azure
345+
# working-directory: ./terraform/azure
181346
# run: terraform fmt -check
182347

183348
- name: Terraform Init
184349
id: init
185-
working-directory: ./examples/azure
350+
working-directory: ./terraform/azure
186351
run: terraform init
187352

188353
- name: Terraform Plan
189354
id: plan
190-
working-directory: ./examples/azure
355+
working-directory: ./terraform/azure
191356
if: github.event_name == 'pull_request'
192357
run: terraform plan -no-color
193358
continue-on-error: true
@@ -224,6 +389,6 @@ jobs:
224389
run: exit 1
225390

226391
- name: Terraform Apply
227-
working-directory: ./examples/azure
392+
working-directory: ./terraform/azure
228393
if: (github.event_name == 'release') || (github.event_name == 'push' && github.ref == 'refs/heads/main')
229394
run: terraform apply -auto-approve

docker-compose.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: "3.7"
2+
services:
3+
server:
4+
image: labflow/script-runner-example:latest
5+
build:
6+
dockerfile: ./docker/Dockerfile.example
7+
context: .
8+
args:
9+
SERVER_VERSION: local+devcontainer
10+
command: "python3 -m flask run --host=0.0.0.0 --port=5000"
11+
environment:
12+
- FLASK_ENV=development
13+
- PORT=5000
14+
- PROPAGATE_EXCEPTIONS=True
15+
- "SERVER_NAME=${SERVER_NAME}"
16+
- "AUTH_PROVIDER=none"
17+
- "CELERY_BROKER_URL=redis://:${REDIS_PASSWORD}@redis:6379"
18+
- "CELERY_RESULT_BACKEND=redis://:${REDIS_PASSWORD}@redis:6379"
19+
ports:
20+
- 5000:5000
21+
volumes:
22+
- ./:/app
23+
worker:
24+
image: labflow/script-runner-example:latest
25+
build:
26+
context: .
27+
dockerfile: ./docker/Dockerfile.example
28+
args:
29+
SERVER_VERSION: local+devcontainer
30+
command: "python3 -m celery -A script_runner.analysis worker"
31+
environment:
32+
- "CELERY_BROKER_URL=redis://:${REDIS_PASSWORD}@redis:6379"
33+
- "CELERY_RESULT_BACKEND=redis://:${REDIS_PASSWORD}@redis:6379"
34+
- "COMMAND_RUNDIR_BASE=/base-rundir"
35+
volumes:
36+
- ./:/app
37+
redis:
38+
image: redis:6-alpine
39+
command: redis-server --requirepass ${REDIS_PASSWORD}
40+
ports:
41+
- 6379:6379

docker/Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
ARG SCRIPT_RUNNER_VERSION=local+container
21
ARG PYTHON_IMAGE_TAG=alpine
32

4-
FROM python:${PYTHON_IMAGE_TAG}}
3+
FROM python:${PYTHON_IMAGE_TAG}
4+
5+
ARG SCRIPT_RUNNER_VERSION=local+container
56

67
WORKDIR /app
78

8-
RUN pip install script-runner-api==${SCRIPT_RUNNER_VERSION}
9+
RUN pip install \
10+
script-runner-api==${SCRIPT_RUNNER_VERSION}
911

1012
COPY ./entrypoint.sh /entrypoint.sh
1113
RUN dos2unix /entrypoint.sh
1214
RUN chmod +x /entrypoint.sh
1315

14-
COPY ./ .
15-
1616
ENV FLASK_APP=script_runner.main:app
1717
ENV SERVER_VERSION=$SERVER_VERSION
1818

0 commit comments

Comments
 (0)