-
Notifications
You must be signed in to change notification settings - Fork 2
98 lines (95 loc) · 3.83 KB
/
workflow.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Build, test and deploy
on:
push:
workflow_dispatch:
inputs:
force_build_live_cluster:
description: "Force live cluster test (yes/no)"
required: true
default: "no"
env:
IMAGE_NAME: "cmdntrf/mc-hub"
RUN_LIVE_CLUSTER_TESTS: ${{ (github.event.inputs.force_build_live_cluster == 'yes' || startsWith(github.ref, 'refs/tags/v')) && 'true' || 'false' }}
MAGIC_CASTLE_VERSION: 12.6.7
jobs:
frontend:
runs-on: ubuntu-22.04
name: Test frontend
steps:
- uses: actions/checkout@v3
- name: Install NPM dependencies
run: (cd frontend && npm ci)
- name: Run frontend unit tests
run: (cd frontend && npm run test:unit)
backend:
runs-on: ubuntu-22.04
name: Test backend
steps:
- uses: actions/checkout@v3
- name: Create run folder
run: |
mkdir -p run
mkdir -p run/database
mkdir -p run/clusters
- name: Decrypt secret files
run: |
FILE_NAMES=('configuration.json' 'gcloud-key.json')
for file_name in "${FILE_NAMES[@]}"
do
gpg --quiet --batch --yes --decrypt --passphrase="$DECRYPTION_PASSPHRASE" \
--output "./run/$file_name" "./.github/secrets/$file_name.gpg"
done
env:
DECRYPTION_PASSPHRASE: ${{ secrets.DECRYPTION_PASSPHRASE }}
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Create virtualenv
working-directory: ./run
run: |
python3 -m venv venv
venv/bin/pip install --upgrade pip
venv/bin/pip install poetry
VIRTUAL_ENV=$PWD/venv venv/bin/poetry install
- name: Fetch Magic Castle Source and patch acme url
working-directory: ./run
run: |
curl -L -O https://github.com/ComputeCanada/magic_castle/releases/download/${MAGIC_CASTLE_VERSION}/magic_castle-openstack-${MAGIC_CASTLE_VERSION}.tar.gz
tar xvf magic_castle-openstack-${MAGIC_CASTLE_VERSION}.tar.gz
mv magic_castle-openstack-${MAGIC_CASTLE_VERSION} magic_castle
sed -i 's;https://acme-v02.api.letsencrypt.org/directory;https://acme-staging-v02.api.letsencrypt.org/directory;g' magic_castle/dns/acme/main.tf
- name: Run backend regular tests
if: ${{ !(env.RUN_LIVE_CLUSTER_TESTS == 'true') }}
working-directory: ./run
run: |
export MAGIC_CASTLE_PATH=$PWD/magic_castle
venv/bin/python -m pytest ../
- name: Run backend extended tests (including live cluster tests)
if: ${{ env.RUN_LIVE_CLUSTER_TESTS == 'true' }}
working-directory: ./run
env:
OS_AUTH_URL: ${{ secrets.OS_AUTH_URL }}
OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }}
OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}
run: |
export MAGIC_CASTLE_PATH=$PWD/magic_castle
venv/bin/python -m pytest -x -vv --build-live-cluster ../;
container:
runs-on: ubuntu-22.04
name: Build container
steps:
- uses: actions/checkout@v3
- name: Build Docker image
if: startsWith(github.ref, 'refs/tags/v')
run: docker build --tag "$IMAGE_NAME" --target production-server .
- name: Deploy to Docker Hub
if: startsWith(github.ref, 'refs/tags/v')
run: |
docker tag "$IMAGE_NAME" "${IMAGE_NAME}:latest"
docker tag "$IMAGE_NAME" "${IMAGE_NAME}:$(git describe --tags --abbrev=0)"
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker push "${IMAGE_NAME}:latest" && docker push "${IMAGE_NAME}:$(git describe --tags --abbrev=0)"
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}