-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (134 loc) · 4.49 KB
/
DeployDocker.yml
File metadata and controls
154 lines (134 loc) · 4.49 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: Docker Image CI/CD
on:
pull_request:
branches:
- main
- develop
types: [opened, closed, synchronize]
release:
types: [published]
jobs:
setup_tag:
name: Setup dockerTag
runs-on: ubuntu-latest
outputs:
docker_tag: ${{ steps.setup_docker_tag.outputs.DockerTag }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup dockerTag
id: setup_docker_tag
run: |
if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.action }}" != "closed" ]]; then
case "${{ github.base_ref }}" in
refs/heads/features/*)
echo "::set-output name=DockerTag::alpha-pr"
;;
"develop")
echo "::set-output name=DockerTag::dev-pr"
;;
"main")
echo "::set-output name=DockerTag::main-pr"
;;
esac
else
case "${{ github.ref }}" in
refs/heads/features/*)
echo "::set-output name=DockerTag::alpha"
;;
"refs/heads/develop")
echo "::set-output name=DockerTag::dev"
;;
"refs/heads/main")
echo "::set-output name=DockerTag::rc"
;;
"refs/tags/*")
echo "::set-output name=DockerTag::release"
;;
esac
fi
build_app:
name: install dependencies and build
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: lts/*
registry-url: https://npm.pkg.github.com/
- name: Set NPM Token
run: echo "//npm.pkg.github.com/:_authToken=${{secrets.GITHUB_TOKEN}}">>.npmrc
- name: Set registry
run: echo "@FullStackMap:registry=https://npm.pkg.github.com">>.npmrc
- name: Install dependencies
run: npm install --force
- name: Build project
run: npm run build
- name: Archive server config files
uses: actions/upload-artifact@v2
with:
name: server-files
path: ./nginx/*
- name: Archive compiled files
uses: actions/upload-artifact@v2
with:
name: compiled-files
path: ./dist/*
CI:
name: Building and deploy Image from-a2b-map
runs-on: ubuntu-latest
needs:
- setup_tag
- build_app
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download server config files artifact
uses: actions/download-artifact@v2
with:
name: server-files
path: ./nginx
- name: Download compiled files artifact
uses: actions/download-artifact@v2
with:
name: compiled-files
path: ./dist
- name: DockerHub login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build Docker Image
run: docker buildx build --platform linux/amd64,linux/arm --file ./Dockerfile.Release --tag ${{ secrets.REGISTRY_NAME }}/from-a2b-map:${{ needs.setup_tag.outputs.docker_tag }} --push .
CD:
name: Update Portainer Service
runs-on: ubuntu-latest
needs: CI
if: ${{ needs.CI.result == 'success' }}
steps:
- name: Send POST request to Portainer webhook
run: |
if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.action }}" == "closed" ]]; then
case "${{ github.ref }}" in
"refs/heads/develop")
curl -X POST -H "Content-Type: application/json" -d '{}' ${{ secrets.FROMA2B_PORTAINER_WEBHOOK_MAP_DEV }}
;;
"refs/heads/main")
curl -X POST -H "Content-Type: application/json" -d '{}' ${{ secrets.FROMA2B_PORTAINER_WEBHOOK_MAP_STAGING }}
;;
"refs/tags/*")
curl -X POST -H "Content-Type: application/json" -d '{}' ${{ secrets.FROMA2B_PORTAINER_WEBHOOK_MAP_RELEASE }}
;;
esac
fi