-
Notifications
You must be signed in to change notification settings - Fork 2
109 lines (83 loc) · 3.1 KB
/
deploy.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
99
100
101
102
103
104
105
106
107
108
109
name: Academy Master Tests
on:
push:
branches: [main]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
- name: Build and push Backend image
id: build-and-push-backend
uses: docker/build-push-action@v4
with:
file: ./backend/docker/Dockerfile
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
test-on-docker:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: SetUp Docker
uses: docker/setup-buildx-action@v2
- name: Pull The Image
run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name: Run Containers
run: make run DETACHED=true
- name: Wait for backend container to prepare
uses: jakejarvis/wait-action@master
with:
time: '5s'
- name: Run tests
run: make test
test-on-kubernetes:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up kubectl
uses: azure/setup-kubectl@v1
- name: Start minikube
uses: medyagh/setup-minikube@master
- name: Create ConfigMap
run: kubectl create configmap academy-master-env --from-env-file=./backend/.env.local && kubectl create configmap academy-master-env-file --from-file=.env=./backend/.env.local
- name: Run Kubernetes Deployments
run: kubectl apply -f kubernetes/
- name: Wait for Test Database Deployments
run: kubectl wait --for=condition=available --timeout=60s deployment/academy-master-test-postgres-dp
- name: Wait for Redis Service
run: kubectl wait --for=condition=available --timeout=60s deployment/academy-master-redis-dp
- name: Wait for Backend Deployments
run: kubectl wait --for=condition=available --timeout=60s deployment/academy-master-backend-dp
- name: Run Backend Tests
run: kubectl exec -it $(kubectl get pods | grep backend | awk '{print $1}') -- pytest
deploy:
needs: [ test-on-docker, test-on-kubernetes ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Fake Deployment
run: echo "Deploying the service to the cloud..."