-
Notifications
You must be signed in to change notification settings - Fork 3
88 lines (75 loc) · 2.47 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
name: Deploy
on:
workflow_run:
workflows:
- Test
branches:
- main
- develop
types:
- completed
workflow_dispatch:
push:
branches:
- poc/docker-multi-stages
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
DOCKER_USERNAME: ${{ github.repository_owner }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
DOCKER_IMAGE: ${{ github.repository }}
jobs:
deploy:
name: Deploy application to Heroku
runs-on: ubuntu-latest
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch || github.ref }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set BRANCH_TAG
uses: nimblehq/branch-tag-action@v1
with:
ref: ${{ github.event.workflow_run.head_branch || github.ref }}
- name: Set HEROKU_APP env variable
run: |
if [[ $BRANCH_TAG = "latest" ]]
then
echo "HEROKU_APP=nimble-survey-web" >> $GITHUB_ENV
else
echo "HEROKU_APP=nimble-survey-web-staging" >> $GITHUB_ENV
fi
- name: Set DOCKER_IMAGE_TAG env variable
run: |
echo "DOCKER_IMAGE_TAG=$DOCKER_REGISTRY/$DOCKER_IMAGE:$BRANCH_TAG" >> $GITHUB_ENV
echo "MAKE UP DOCKER IMAGE TAG"
echo $DOCKER_IMAGE_TAG
- name: Prepare Docker image
run: |
bin/docker-prepare
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_TOKEN }}
- name: Docker build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.DOCKER_IMAGE_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Log in to Heroku container
run: heroku container:login
- name: Publish application
run: |
heroku container:push --arg DOCKER_REGISTRY=$DOCKER_REGISTRY,DOCKER_IMAGE=$DOCKER_IMAGE,BRANCH_TAG=$BRANCH_TAG --recursive
heroku container:release web worker