-
Notifications
You must be signed in to change notification settings - Fork 1
105 lines (95 loc) · 3.74 KB
/
codeforafrica-deploy-review-app.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
name: Code for Africa | Deploy | REVIEW APP
on:
pull_request:
paths:
- "apps/codeforafrica/**"
- "Dockerfile.codeforafrica"
- ".github/**"
concurrency:
group: "${{ github.workflow }} @ ${{ github.ref }}"
cancel-in-progress: false
env:
DOKKU_REMOTE_BRANCH: "master"
DOKKU_REMOTE_URL: "ssh://[email protected]"
IMAGE_NAME: "codeforafrica/codeforafrica-ui"
ORIGINAL_APP_NAME: "codeforafrica-ui"
NEXT_PUBLIC_APP_URL: "https://codeforafrica-ui-pr-${{github.event.pull_request.number}}.dev.codeforafrica.org"
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APP_NAME: codeforafrica-ui-pr-${{ github.event.pull_request.number }}
jobs:
review_app:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [18]
os: [ubuntu-latest]
if: github.event_name == 'pull_request' && github.event.action != 'closed'
steps:
- name: Cloning repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
key: ${{ runner.os }}-buildx-${{ github.sha }}
path: /tmp/.buildx-cache
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v2
with:
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
username: ${{ secrets.DOCKER_HUB_USERNAME }}
- name: Build Docker image
uses: docker/build-push-action@v3
with:
build-args: |
MONGODB_URL=${{ secrets.CODEFORAFRICA_MONGO_URL }}/${{ env.APP_NAME }}
NEXT_PUBLIC_APP_URL=${{ env.NEXT_PUBLIC_APP_URL }}
PAYLOAD_SECRET=${{ secrets.CODEFORAFRICA_PAYLOAD_SECRET_KEY }}
GHOST_URL=${{ secrets.GHOST_URL }}
GHOST_API_KEY=${{ secrets.GHOST_API_KEY }}
NEXT_PUBLIC_APP_LOGO_URL=${{ secrets.NEXT_PUBLIC_APP_CFA_LOGO_URL }}
NEXT_PUBLIC_APP_NAME=${{ secrets.NEXT_PUBLIC_APP_CFA_NAME }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
context: .
file: ./Dockerfile.codeforafrica
push: true
tags: "${{ env.IMAGE_NAME }}:${{ github.sha }}"
- name: Push to dokku
uses: dokku/github-action@master
with:
# create a review app
command: review-apps:create
git_remote_url: ${{ env.DOKKU_REMOTE_URL }}/codeforafrica-ui
# specify a name for the review app
review_app_name: ${{ env.APP_NAME }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
deploy_docker_image: ${{ env.IMAGE_NAME }}:${{ github.sha }}
- name: Update Preview URL
run: (gh pr comment ${{ env.issue-number }} --edit-last --body='${{ env.body }}' || gh pr comment ${{ env.issue-number }} --body='${{ env.body }}')
env:
issue-number: ${{ github.event.pull_request.number }}
body: |
Latest updated Preview URL
| Name | Review |
|-------|--------|
| ${{ env.APP_NAME }} | [Visit](https://${{ env.APP_NAME }}.dev.codeforafrica.org) |
destroy_review_app:
runs-on: ubuntu-latest
# only run when a pull request is closed
if: github.event.action == 'closed'
steps:
- name: Destroy the review app
uses: dokku/github-action@master
with:
# destroy a review app
command: review-apps:destroy
git_remote_url: ${{ env.DOKKU_REMOTE_URL }}/${{ env.APP_NAME }}
# specify a name for the review app
review_app_name: ${{ env.APP_NAME }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}