-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (112 loc) · 4.65 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
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
115
116
117
118
119
120
121
122
name: CI/CD
on: [push]
env:
NODE_VERSION: '14.16.0'
IMAGE_NAME: griffonnage/griffonnage-sync
IMAGE_TAG: latest
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache Node.js modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
- name: Install dependencies
run: npm install
- name: Check dependencies
run: npm audit --production
- name: Check code lint
run: npm run lint
# - name: Run tests
# run: npm run test:ci
# - name: Publish code coverage to Codecov
# uses: codecov/codecov-action@v1
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
build-docker:
name: Docker build
runs-on: ubuntu-latest
needs: test
if: contains(github.ref, 'master') || contains(github.ref, 'tags')
steps:
- uses: actions/checkout@v2
- name: Select Docker image tag (production only)
if: contains(github.ref, 'tags')
run: echo "::set-env name=IMAGE_TAG::${GITHUB_REF##*/}"
- name: Log into Docker Registry
run: echo ${{ secrets.DOCKER_TOKEN }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Pull latest Docker image
run: docker pull $IMAGE_NAME:latest || true
- name: Build Docker image (${{ env.IMAGE_TAG }})
run: docker build -t $IMAGE_NAME:$IMAGE_TAG --cache-from $IMAGE_NAME:latest .
- name: Push Docker image
run: |
docker push $IMAGE_NAME:$IMAGE_TAG
deploy-staging:
name: Deploy Staging
needs: build-docker
runs-on: ubuntu-latest
if: contains(github.ref, 'master')
steps:
- uses: actions/checkout@v2
- run: git fetch --prune --unshallow
- name: Deploy to Heroku
env:
HEROKU_APP_ID: ${{ secrets.HEROKU_APP_ID_STAGING }}
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
run: |
sudo apt-get install --assume-yes --no-install-recommends curl
echo ${{ secrets.DOCKER_TOKEN }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
docker pull $IMAGE_NAME:$IMAGE_TAG
docker tag $IMAGE_NAME:$IMAGE_TAG registry.heroku.com/$HEROKU_APP_ID
IMAGE_ID=$(docker inspect $IMAGE_NAME:$IMAGE_TAG --format="{{.Id}}")
docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
docker push registry.heroku.com/$HEROKU_APP_ID
curl -X PATCH https://api.heroku.com/apps/$HEROKU_APP_ID/formation \
--header "Content-Type: application/json" \
--header "Accept: application/vnd.heroku+json; version=3.docker-releases" \
--header "Authorization: Bearer ${HEROKU_API_KEY}" \
--data '{ "updates": [ { "type": "web", "docker_image": "'$IMAGE_ID'" } ] }'
deploy-production:
name: Deploy Production
needs: build-docker
runs-on: ubuntu-latest
if: contains(github.ref, 'tags')
steps:
- uses: actions/checkout@v2
- run: git fetch --prune --unshallow
- name: Deploy to Heroku
env:
HEROKU_APP_ID: ${{ secrets.HEROKU_APP_ID_PRODUCTION }}
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
run: |
sudo apt-get install --assume-yes --no-install-recommends curl
echo ${{ secrets.DOCKER_TOKEN }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
echo "::set-env name=IMAGE_TAG::${GITHUB_REF##*/}"
docker pull $IMAGE_NAME:$IMAGE_TAG
docker tag $IMAGE_NAME:$IMAGE_TAG registry.heroku.com/$HEROKU_APP_ID
IMAGE_ID=$(docker inspect $IMAGE_NAME:$IMAGE_TAG --format="{{.Id}}")
docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
docker push registry.heroku.com/$HEROKU_APP_ID
curl -X PATCH https://api.heroku.com/apps/$HEROKU_APP_ID/formation \
--header "Content-Type: application/json" \
--header "Accept: application/vnd.heroku+json; version=3.docker-releases" \
--header "Authorization: Bearer ${HEROKU_API_KEY}" \
--data '{ "updates": [ { "type": "web", "docker_image": "'$IMAGE_ID'" } ] }'
- name: Deploy to CleverCloud
uses: 47ng/actions-clever-cloud@v1
with:
appID: ${{ secrets.CLEVER_APP_ID_PRODUCTION }}
env:
CLEVER_TOKEN: ${{ secrets.CLEVER_TOKEN }}
CLEVER_SECRET: ${{ secrets.CLEVER_SECRET }}