-
Notifications
You must be signed in to change notification settings - Fork 14
104 lines (90 loc) · 3.04 KB
/
nodejs_docker.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
name: cicd
on:
push:
branches:
- dev
- master
tags:
- v*
pull_request:
env:
IMAGE_NAME: frontend
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build --if-present
- run: npm test
env:
CI: true
- name: test
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build . --file Dockerfile
fi
- name: Build image
if: github.event_name == 'push'
run: docker build . --file Dockerfile --tag image
- name: Log into registry
if: github.event_name == 'push'
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Push image
if: github.event_name == 'push'
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention for master branch
[ "$VERSION" == "master" ] && VERSION=latest-${{ github.sha }}
# Use Docker `dev` tag convention for dev branch
[ "$VERSION" == "dev" ] && VERSION=dev
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag image $IMAGE_ID:$VERSION
docker tag image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
deploy:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
- name: K8S set context
uses: azure/k8s-set-context@v1
with:
method: kubeconfig
kubeconfig: ${{ secrets.K8S_Context }}
id: setcontext
- name: K8S create secret
uses: Azure/k8s-create-secret@v1
with:
container-registry-url: docker.pkg.github.com
container-registry-username: ${{ secrets.REGISTRY_USERNAME }}
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
secret-name: github-k8s-secret
- name: K8S deploy
uses: Azure/k8s-deploy@v1
with:
namespace: 'default'
manifests: |
manifests/fe-deployment.yaml
manifests/fe-service.yaml
images: |
docker.pkg.github.com/wuhan-support/frontend/frontend:latest-${{ github.sha }}
imagepullsecrets: |
github-k8s-secret
kubectl-version: 'latest'