-
Notifications
You must be signed in to change notification settings - Fork 3
49 lines (39 loc) · 1.68 KB
/
main.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
name: Build and deploy
on: [push]
env:
DOCKER_IMAGE_NAME: dhcenter/st-retrospect-admin
jobs:
build_and_deploy:
runs-on: ubuntu-18.04
steps:
- name: Checkout repository
uses: actions/checkout@v1
- uses: nelonoel/[email protected]
- name: Make envfile
uses: SpicyPizza/create-envfile@v1
with:
envkey_REACT_APP_MAPBOX_ACCESS_TOKEN: ${{ secrets.REACT_APP_MAPBOX_ACCESS_TOKEN }}
envkey_REACT_APP_API_ENDPOINT: ${{ secrets.REACT_APP_API_ENDPOINT }}
envkey_REACT_APP_SENTRY_DNS: ${{ secrets.REACT_APP_SENTRY_DNS }}
- name: Change API endpoint if prod
if: endsWith(github.ref, '/prod')
run: sed -i -E "s/api.stage.st-retrospect/api.st-retrospect/" .env
- name: Build the Docker image
run: docker build . -t $DOCKER_IMAGE_NAME
- name: Set deploy command to env variable
run: echo "DEPLOY_COMMAND=$(echo "cd ~/retrospect/${BRANCH_NAME}/admin && ./deploy.sh")" >> $GITHUB_ENV
- name: Push to Docker Hub
if: endsWith(github.ref, '/stage') || endsWith(github.ref, '/prod')
run: |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$BRANCH_NAME
docker push $DOCKER_IMAGE_NAME:$BRANCH_NAME
docker logout
- name: Deploy
if: endsWith(github.ref, '/stage') || endsWith(github.ref, '/prod')
uses: garygrossgarten/[email protected]
with:
command: ${{ env.DEPLOY_COMMAND }}
host: ${{ secrets.SERVER_HOST }}
username: root
privateKey: ${{ secrets.PRIVATE_KEY }}