Skip to content

Commit 3ce1928

Browse files
authored
Merge pull request #19 from UKPLab/github-actions-initial-setup
Create CI/CD pipeline
2 parents b2fd35d + ec60a7e commit 3ce1928

File tree

8 files changed

+229
-30
lines changed

8 files changed

+229
-30
lines changed

.github/workflows/cd.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: CD
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
workflow_dispatch:
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
13+
- name: Webhook
14+
uses: distributhor/workflow-webhook
15+
with:
16+
url: "http://${{ secrets.VM_IP }}:${{ secrets.VM_WEBHOOK_PORT }}/hooks/redeploy-webhook"
17+
json: '{ webhook_token: ${{secrets.WEBHOOK_TOKEN}} }'

.github/workflows/ci.yml

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
workflow_dispatch:
10+
11+
jobs:
12+
backend:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Prepare
19+
id: prep
20+
run: |
21+
TAG=$(echo $GITHUB_SHA | head -c7)
22+
IMAGE="ukpsquare/square-backend"
23+
echo ::set-output name=image::${IMAGE}
24+
echo ::set-output name=tag::${TAG}
25+
- name: Set up Docker Buildx
26+
id: buildx
27+
uses: docker/setup-buildx-action@v1
28+
with:
29+
install: true
30+
31+
- name: Cache Docker layers
32+
uses: actions/cache@v2
33+
with:
34+
path: /tmp/.buildx-cache
35+
key: ${{ runner.os }}-buildx-backend-${{ github.sha }}
36+
restore-keys: |
37+
${{ runner.os }}-buildx-backend-
38+
${{ runner.os }}-buildx-
39+
40+
- name: Build test image
41+
uses: docker/build-push-action@v2
42+
with:
43+
builder: ${{ steps.buildx.outputs.name }}
44+
context: ./square-backend
45+
target: test
46+
load: true
47+
tags: ${{ steps.prep.outputs.image }}:${{ steps.prep.outputs.tag }}-test
48+
cache-from: type=local,src=/tmp/.buildx-cache
49+
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
50+
51+
52+
# Temp fix
53+
# https://github.com/docker/build-push-action/issues/252
54+
# https://github.com/moby/buildkit/issues/1896
55+
- name: Move cache
56+
run: |
57+
rm -rf /tmp/.buildx-cache
58+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
59+
60+
- name: Retrieve Test Reports
61+
id: extract
62+
uses: shrink/actions-docker-extract@v1
63+
with:
64+
image: ${{ steps.prep.outputs.image }}:${{ steps.prep.outputs.tag }}-test
65+
path: /app/test-reports
66+
67+
- uses: actions/upload-artifact@v2
68+
with:
69+
name: backend-test-reports
70+
path: ${{ steps.extract.outputs.destination }}/test-reports
71+
72+
- name: Publish Test Report
73+
uses: mikepenz/action-junit-report@v2
74+
with:
75+
report_paths: ${{ steps.extract.outputs.destination }}/test-reports/junit.xml
76+
check_name: Backend Test Report
77+
fail_on_failure: true
78+
79+
- name: Login to Docker Hub
80+
uses: docker/login-action@v1
81+
with:
82+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
83+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
84+
85+
- name: Build deployable image
86+
uses: docker/build-push-action@v2
87+
with:
88+
builder: ${{ steps.buildx.outputs.name }}
89+
context: ./square-backend
90+
target: build
91+
push: ${{github.ref == 'refs/heads/master'}}
92+
tags: ${{ steps.prep.outputs.image }}:${{ steps.prep.outputs.tag }}, ${{ steps.prep.outputs.image }}:latest
93+
cache-from: type=local,src=/tmp/.buildx-cache
94+
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
95+
96+
# Temp fix
97+
# https://github.com/docker/build-push-action/issues/252
98+
# https://github.com/moby/buildkit/issues/1896
99+
- name: Move cache
100+
run: |
101+
rm -rf /tmp/.buildx-cache
102+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
103+
frontend:
104+
runs-on: ubuntu-latest
105+
steps:
106+
- uses: actions/checkout@v2
107+
108+
- name: Prepare
109+
id: prep
110+
run: |
111+
TAG=$(echo $GITHUB_SHA | head -c7)
112+
IMAGE="ukpsquare/square-frontend"
113+
echo ::set-output name=image::${IMAGE}
114+
echo ::set-output name=tag::${TAG}
115+
- name: Set up Docker Buildx
116+
id: buildx
117+
uses: docker/setup-buildx-action@v1
118+
with:
119+
install: true
120+
121+
- name: Cache Docker layers
122+
uses: actions/cache@v2
123+
with:
124+
path: /tmp/.buildx-cache
125+
key: ${{ runner.os }}-buildx-frontend-${{ github.sha }}
126+
restore-keys: |
127+
${{ runner.os }}-buildx-frontend-
128+
${{ runner.os }}-buildx-
129+
130+
- name: Login to Docker Hub
131+
uses: docker/login-action@v1
132+
with:
133+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
134+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
135+
136+
- name: Build deployable image
137+
uses: docker/build-push-action@v2
138+
with:
139+
builder: ${{ steps.buildx.outputs.name }}
140+
context: ./square-frontend
141+
target: build
142+
push: ${{github.ref == 'refs/heads/master'}}
143+
tags: ${{ steps.prep.outputs.image }}:${{ steps.prep.outputs.tag }}, ${{ steps.prep.outputs.image }}:latest
144+
cache-from: type=local,src=/tmp/.buildx-cache
145+
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
146+
147+
# Temp fix
148+
# https://github.com/docker/build-push-action/issues/252
149+
# https://github.com/moby/buildkit/issues/1896
150+
- name: Move cache
151+
run: |
152+
rm -rf /tmp/.buildx-cache
153+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
*iml
33
# Byte-compiled / optimized / DLL files
44
__pycache__/
5-
*.py[cod]
5+
*.py[cod]
6+
.venv

docker-compose.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
- db-data:/var/lib/postgresql/data
1515

1616
backend:
17-
build: ./square-backend
17+
image: ukpsquare/square-backend:latest
1818
restart: always
1919
ports:
2020
- 5000:5000
@@ -24,7 +24,7 @@ services:
2424
- migrations-data:/app/migrations
2525

2626
frontend:
27-
build: ./square-frontend
27+
image: ukpsquare/square-frontend:latest
2828
restart: always
2929
ports:
3030
- 80:80
@@ -35,22 +35,22 @@ services:
3535
# ports:
3636
# - 8080:8080
3737

38-
es:
39-
image: docker.elastic.co/elasticsearch/elasticsearch:7.5.0
40-
environment:
41-
- node.name=es01
42-
- cluster.name=es-docker-cluster
43-
- discovery.type=single-node
44-
- bootstrap.memory_lock=true
45-
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
46-
ulimits:
47-
memlock:
48-
soft: -1
49-
hard: -1
50-
volumes:
51-
- es01:/usr/share/elasticsearch/data
52-
ports:
53-
- 9200:9200
38+
# es:
39+
# image: docker.elastic.co/elasticsearch/elasticsearch:7.5.0
40+
# environment:
41+
# - node.name=es01
42+
# - cluster.name=es-docker-cluster
43+
# - discovery.type=single-node
44+
# - bootstrap.memory_lock=true
45+
# - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
46+
# ulimits:
47+
# memlock:
48+
# soft: -1
49+
# hard: -1
50+
# volumes:
51+
# - es01:/usr/share/elasticsearch/data
52+
# ports:
53+
# - 9200:9200
5454

5555
volumes:
5656
db-data:

square-backend/Dockerfile

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
1-
FROM python:3.7.6
1+
FROM python:3.7.6-slim-buster as base
22

3-
COPY requirements.txt /app/requirements.txt
4-
RUN pip install -r /app/requirements.txt
3+
RUN pip install --upgrade pip
4+
5+
WORKDIR /app
6+
7+
COPY requirements.txt requirements.txt
8+
RUN pip install -r requirements.txt
59
# not in requirements because we use SQLite for dev server
610
RUN pip install psycopg2
711

8-
COPY ./squareapi /app/squareapi
9-
COPY flask-manage.py /app/flask-manage.py
10-
COPY main.py /app/main.py
11-
COPY ./docker /app
12+
COPY ./docker .
13+
COPY flask-manage.py flask-manage.py
14+
COPY main.py main.py
15+
COPY ./squareapi squareapi
1216

1317
WORKDIR /app
1418
RUN mkdir -p logs
1519

20+
FROM base as test
21+
WORKDIR /app
22+
RUN pip install pytest pytest-cov
23+
COPY ./tests tests
24+
RUN mkdir test-reports
25+
RUN pytest \
26+
--junitxml=test-reports/junit.xml \
27+
--cov \
28+
--cov-report=xml:test-reports/coverage.xml \
29+
--cov-report=html:test-reports/coverage.html; \
30+
echo $? > test-reports/pytest.existcode
31+
32+
FROM base as build
33+
1634
RUN ["chmod", "+x", "./entry.sh"]
1735
ENTRYPOINT ["./entry.sh"]

square-backend/tests/__init__.py

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pytest
2+
from squareapi.skill.skill_selector import SkillSelector
3+
4+
5+
@pytest.fixture
6+
def skill_selector():
7+
return SkillSelector()
8+
9+
def test_skill_selector(skill_selector: SkillSelector):
10+
assert len(skill_selector.skills) == 0

square-frontend/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# From https://medium.com/@tiangolo/react-in-docker-with-nginx-built-with-multi-stage-docker-builds-including-testing-8cc49d6ec305
22

33
# Stage 0, "build-stage", based on Node.js, to build and compile the frontend
4-
FROM tiangolo/node-frontend:10 as build-stage
4+
FROM tiangolo/node-frontend:10 as base
55
WORKDIR /app
66
COPY package*.json /app/
77
RUN npm install
88
COPY ./ /app/
99
RUN npm run build
1010

1111
# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx
12-
FROM nginx:1.15
13-
COPY --from=build-stage /app/dist/ /usr/share/nginx/html
12+
FROM nginx:1.15 as build
13+
COPY --from=base /app/dist/ /usr/share/nginx/html
1414
# Copy the default nginx.conf provided by tiangolo/node-frontend
15-
COPY --from=build-stage /nginx.conf /etc/nginx/conf.d/default.con
15+
COPY --from=base /nginx.conf /etc/nginx/conf.d/default.con

0 commit comments

Comments
 (0)