Skip to content

Commit dce79ed

Browse files
authored
Merge pull request getslash#647 from parallelsystems/build-deploy-docker-img
Add a docker build action for github
2 parents b94a0fc + 025e7af commit dce79ed

File tree

8 files changed

+568
-329
lines changed

8 files changed

+568
-329
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ webapp/tmp/*
88
/_assets_src/*
99
/api-server/target/*
1010
/.git
11+
/.github

.github/workflows/build_docker.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# This workflow builds the docker image on any PR or Release
2+
# Releases will be tagged with latest, stable, and their git tag
3+
# Prereleases will be tagged with prerelease and their git tag
4+
# Pull Requests will be tagged with branch name and their github ref (pr-{number})
5+
6+
name: Create and publish a Docker image
7+
8+
on:
9+
release:
10+
types: [published]
11+
12+
pull_request:
13+
branches:
14+
- '*'
15+
env:
16+
REGISTRY: ghcr.io
17+
IMAGE_NAME: ${{ github.repository }}
18+
RELEASE: ${{ github.event.release != null && github.event.release.prerelease != true }}
19+
PRERELEASE: ${{ github.event.release != null && github.event.release.prerelease == true }}
20+
21+
22+
jobs:
23+
build-and-push-image:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
packages: write
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v2
32+
33+
- name: Setup Python
34+
uses: actions/setup-python@v2
35+
with:
36+
python-version: "3.9"
37+
38+
- name: Log in to the Container registry
39+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
40+
with:
41+
registry: ${{ env.REGISTRY }}
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Fix versions
46+
run: python scripts/github_version_fix.py
47+
48+
- name: Setup docker buildx
49+
uses: docker/setup-buildx-action@v1
50+
id: buildx
51+
with:
52+
install: true
53+
- name: Extract metadata (tags, labels) for Docker
54+
id: meta
55+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
56+
with:
57+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
58+
flavor: |
59+
latest=${{ env.RELEASE }}
60+
tags: |
61+
type=ref, event=tag, enable=true
62+
type=ref, event=branch, enable=true
63+
type=ref, event=pr, enable=true
64+
type=raw, value=prerelease, enable=${{ env.PRERELEASE }}
65+
type=raw, value=stable, enable=${{ env.RELEASE }}
66+
type=raw, value=${{ github.head_ref }}, enable=${{ github.event.pull_request != null}}
67+
68+
- name: Build and push Docker image
69+
uses: docker/[email protected]
70+
with:
71+
context: .
72+
file: docker/Dockerfile
73+
push: ${{ github.event.release != null }}
74+
tags: ${{ steps.meta.outputs.tags }}
75+
labels: ${{ steps.meta.outputs.labels }}
76+
cache-from: type=gha
77+
cache-to: type=gha,mode=max

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Setup Python
3434
uses: actions/setup-python@v2
3535
with:
36-
python-version: "3.6"
36+
python-version: "3.9"
3737
- run: pip install pipenv
3838
- name: Check out repository code
3939
uses: actions/checkout@v2

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Version 2.18.0
4+
5+
Moved Python to 3.9 and update the docker container to use Ubuntu 20.04
6+
7+
38
## Version 2.17.3
49

510
**NOTE**: the default `BACKSLASH_DATABASE_URI` has been changed in this release (in

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ tmuxp = "*"
5353
yarl = "*"
5454

5555
[requires]
56-
python_version = "3.6"
56+
python_version = "3.9"
5757

5858
[scripts]
5959
manage = "python manage.py"

Pipfile.lock

Lines changed: 448 additions & 321 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ ADD ./api-server /api-server
1111
RUN sudo chown -R rust:rust /api-server
1212
RUN cd /api-server && rm -rf target && cargo test --release && cargo build --release
1313

14-
FROM ubuntu:16.04
14+
FROM ubuntu:20.04
1515

16-
env PYTHON_VERSION 3.6
17-
env PYTHON_EXECUTABLE python$PYTHON_VERSION
16+
ENV PYTHON_VERSION 3.9
17+
ENV PYTHON_EXECUTABLE python$PYTHON_VERSION
1818

19-
env LC_ALL C.UTF-8
20-
env LANG C.UTF-8
19+
ENV LC_ALL C.UTF-8
20+
ENV LANG C.UTF-8
21+
22+
ENV DEBIAN_FRONTEND noninteractive
2123

2224
RUN apt-get update
2325
RUN apt-get -y install build-essential software-properties-common libpq-dev nginx curl redis-server gcc sudo libsasl2-dev libldap2-dev wget git
@@ -34,7 +36,7 @@ RUN ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/
3436

3537
RUN add-apt-repository ppa:deadsnakes/ppa
3638
RUN apt-get update
37-
RUN apt-get install -y $PYTHON_EXECUTABLE $PYTHON_EXECUTABLE-dev
39+
RUN apt-get install -y $PYTHON_EXECUTABLE $PYTHON_EXECUTABLE-dev $PYTHON_EXECUTABLE-distutils
3840

3941
RUN wget https://bootstrap.pypa.io/get-pip.py -O /tmp/get-pip.py
4042
RUN $PYTHON_EXECUTABLE /tmp/get-pip.py

scripts/github_version_fix.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
3+
if __name__ == "__main__":
4+
github_ref_type = os.environ.get('GITHUB_REF_TYPE')
5+
github_sha = os.environ.get("GITHUB_SHA")
6+
github_ref_name = os.environ.get("GITHUB_REF_NAME")
7+
github_event_name = os.environ.get("GITHUB_EVENT_NAME")
8+
github_head_ref = os.environ.get("GITHUB_HEAD_REF")
9+
10+
if github_ref_type == "tag":
11+
# Use tag for version if it exists
12+
version = github_ref_name
13+
elif github_event_name == "pull_request":
14+
# For pull requests use the branch, short SHA and the ref (pr-#)
15+
version = f"{github_head_ref}_{github_sha[:8]}_{github_ref_name}"
16+
elif github_event_name != "pull_request" and github_ref_type == "branch":
17+
# For pushes to branch use branch and short SHA
18+
version = f"{github_ref_name}_{github_sha[:8]}"
19+
else:
20+
# For any other situations use the full SHA
21+
version = github_sha
22+
23+
with open('flask_app/__version__.py', 'w') as f:
24+
print(f'__version__ = "{version}"', file=f)
25+
26+
with open('webapp/app/utils/ui_version.js', 'w') as f:
27+
print(f'export default "{version}";', file=f)

0 commit comments

Comments
 (0)