-
Notifications
You must be signed in to change notification settings - Fork 3
115 lines (91 loc) · 3.56 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
110
111
112
113
114
name: Deploy to Heroku
on:
push:
branches:
- dev
- release/*
jobs:
# Step 1: Testing using Jest
Test-Client:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '16.x' # Use the version of Node.js your project requires
- name: Install dependencies for the client
run: |
cd code/client
npm ci
- name: Run Jest tests
run: |
cd code/client
npm test
# Step 2: Testing using Jest
Test-Server:
runs-on: ubuntu-latest
needs: Test-Client
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '16.x' # Use the version of Node.js your project requires
- name: Install dependencies for the server
run: |
cd code/server
npm ci
- name: Run Jest tests
run: |
cd code/server
npm test
# Step 3: Deployment job depends on successful completion of tests
Deploy:
runs-on: ubuntu-latest
needs: Test-Server # This ensures that the deploy job runs only if the test job succeeds
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
HEROKU_EMAIL: ${{ secrets.HEROKU_EMAIL }}
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP_NAME_CLIENT: ${{ secrets.HEROKU_APP_NAME_CLIENT }}
HEROKU_APP_NAME_SERVER: ${{ secrets.HEROKU_APP_NAME_SERVER }}
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Login to DockerHub Registry
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Move heroku.yml to root
run: cp code/heroku.yml ./heroku.yml
- name: Move Procfile to root
run: cp code/Procfile ./Procfile
- name: Log in to Heroku Container Registry
run: |
echo "$HEROKU_API_KEY" | docker login --username="$HEROKU_EMAIL" --password-stdin registry.heroku.com
- name: Install Docker Compose
run: |
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
- name: Build Images Using Docker Compose
run: |
docker-compose -f code/docker-compose-production.yml --project-directory ./code build
- name: Tag and Push API Image to Heroku Container Registry
run: |
docker tag api-production:latest registry.heroku.com/${{ env.HEROKU_APP_NAME_SERVER }}/web
docker push registry.heroku.com/${{ env.HEROKU_APP_NAME_SERVER }}/web
- name: Tag and Push Client Image to Heroku Container Registry
run: |
docker tag client-production:latest registry.heroku.com/${{ env.HEROKU_APP_NAME_CLIENT }}/web
docker push registry.heroku.com/${{ env.HEROKU_APP_NAME_CLIENT }}/web
- name: Release the API on Heroku
run: |
heroku container:release web --app ${{ env.HEROKU_APP_NAME_SERVER }}
- name: Release the Client on Heroku
run: |
heroku container:release web --app ${{ env.HEROKU_APP_NAME_CLIENT }}