-
Notifications
You must be signed in to change notification settings - Fork 1
71 lines (60 loc) · 2.34 KB
/
ci-cd.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
name: CI-CD
on:
push:
branches: [ "main", "dev" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.16.0]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Set environment variables for staging
if: contains(github.ref, 'dev')
run: echo "${{ secrets.STAGING_ENV }}" > .env
- name: Set environment variables for prod
if: contains(github.ref, 'main')
run: echo "${{ secrets.PRODUCTION_ENV }}" > .env
- name: Docker build and push to dev
if: contains(github.ref, 'dev')
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_REPO }}/clubber-front-dev .
docker push ${{ secrets.DOCKER_REPO }}/clubber-front-dev
- name: Docker build and push to prod
if: contains(github.ref, 'main')
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_REPO }}/clubber-front-prod .
docker push ${{ secrets.DOCKER_REPO }}/clubber-front-prod
- name: Deploy to dev
if: contains(github.ref, 'dev')
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
sudo docker rm -f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_REPO }}/clubber-front-dev
sudo docker-compose -f docker-compose-dev.yml up -d
docker image prune -f
- name: Deploy to prod
if: contains(github.ref, 'main')
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST_PROD }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY_PROD }}
port: ${{ secrets.SSH_PORT }}
script: |
sudo docker rm -f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_REPO }}/clubber-front-prod
sudo docker-compose -f docker-compose-prod.yml up -d
docker image prune -f