-
Notifications
You must be signed in to change notification settings - Fork 3
183 lines (177 loc) · 6.79 KB
/
push_master.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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: 'push: master'
on:
push:
branches:
- master
jobs:
skip:
name: Check release skip
runs-on: ubuntu-latest
if: "! contains(github.event.head_commit.message, '[release skip]')"
steps:
- run: echo "${{ github.event.head_commit.message }}"
dockle:
name: Dockle scan
runs-on: ubuntu-latest
needs: [skip]
steps:
- uses: actions/checkout@master
- run: docker login --username ${{ secrets.DOCKER_HUB_USER }} --password ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build docker image
run: docker build ./ -t ${IMAGE_NAME} --file Dockerfile
- name: Install dockle
run: |
VERSION=$(curl --silent "https://api.github.com/repos/goodwithtech/dockle/releases/latest" | \
grep '"tag_name":' | \
sed -E 's/.*"v([^"]+)".*/\1/' \
)
curl -L -o dockle.deb https://github.com/goodwithtech/dockle/releases/download/v${VERSION}/dockle_${VERSION}_Linux-64bit.deb
sudo dpkg -i dockle.deb
rm dockle.deb
- name: Check image with dockle
# CIS-DI-0001: Create a user for the container
# DKL-DI-0006: Avoid latest tag
run: dockle -i CIS-DI-0001 -i DKL-DI-0006 ${IMAGE_NAME}
- name: Slack Notification
uses: 8398a7/action-slack@v2
if: cancelled() || failure()
with:
status: ${{ job.status }}
author_name: ProjectPrimera/ongeki-score
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TEST }}
env:
IMAGE_NAME: projectprimera/ongeki-score
trivy:
name: Trivy scan
runs-on: ubuntu-latest
needs: [skip]
steps:
- uses: actions/checkout@master
- run: docker login --username ${{ secrets.DOCKER_HUB_USER }} --password ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build docker image
run: docker build ./ -t ${IMAGE_NAME} --file Dockerfile
- name: Install trivy
run: |
sudo apt-get install apt-transport-https gnupg
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -cs) main | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy
- name: Vulnerability scan with trivy
run: trivy -q image ${IMAGE_NAME}
- name: Slack Notification
uses: 8398a7/action-slack@v2
if: cancelled() || failure()
with:
status: ${{ job.status }}
author_name: ProjectPrimera/ongeki-score
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TEST }}
env:
IMAGE_NAME: projectprimera/ongeki-score
publish:
name: Publish to Docker Hub
runs-on: ubuntu-latest
needs: [skip, dockle, trivy]
steps:
- uses: actions/checkout@master
- run: echo ${{ secrets.DOCKER_HUB_TOKEN }} | docker login --username ${{ secrets.DOCKER_HUB_USER }} --password-stdin
- run: echo ${{ secrets.GH_AUTH_TOKEN }} | docker login docker.pkg.github.com --username ${{ secrets.GH_AUTH_USER }} --password-stdin
- shell: bash
id: validate
run: |
VERSION='${{github.event.head_commit.message}}'
if [[ $VERSION =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then
echo "::set-output name=version::${BASH_REMATCH[1]}"
else
exit 1
fi
- name: Get commit commit
id: hash
run: echo "::set-output name=hash::"$(git rev-parse --short HEAD)
- name: Build docker image
run: docker build ./ -t ${IMAGE_NAME} --file Dockerfile --build-arg application_version=${{steps.validate.outputs.version}} --build-arg commit_hash=${{steps.hash.outputs.hash}}
- run: |
docker tag ${IMAGE_NAME} ${IMAGE_NAME}:latest
docker tag ${IMAGE_NAME} ${IMAGE_NAME_GITHUB}:latest
TAG=${{steps.validate.outputs.version}}
docker tag ${IMAGE_NAME} ${IMAGE_NAME}:${TAG}
docker tag ${IMAGE_NAME} ${IMAGE_NAME_GITHUB}:${TAG}
- name: Publish
run: |
TAG=${{steps.validate.outputs.version}}
docker push ${IMAGE_NAME}:${TAG}
docker push ${IMAGE_NAME}:latest
# docker push ${IMAGE_NAME_GITHUB}:${TAG}
# docker push ${IMAGE_NAME_GITHUB}:latest
- name: Slack Notification
uses: 8398a7/action-slack@v2
if: always()
with:
status: ${{ job.status }}
author_name: ProjectPrimera/ongeki-score
text: <!channel>
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
env:
IMAGE_NAME: projectprimera/ongeki-score
IMAGE_NAME_GITHUB: docker.pkg.github.com/project-primera/ongeki-score/ongeki-score
# release:
# name: Create Release
# runs-on: ubuntu-latest
# needs: [skip, dockle, trivy, publish]
# steps:
# - uses: actions/checkout@v2
# - shell: bash
# id: validate
# run: |
# VERSION='${{github.event.head_commit.message}}'
# if [[ $VERSION =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then
# echo "::set-output name=version::${BASH_REMATCH[1]}"
# else
# exit 1
# fi
# - shell: bash
# name: Make tag test.
# run: |
# git tag ${{steps.validate.outputs.version}}
# git tag -d ${{steps.validate.outputs.version}}
# - shell: bash
# id: changelog
# run: |
# git fetch --prune --unshallow
# yarn install --production=false
# description=$(yarn run --silent changelog | sed -e 's/^## .*$//' | sed -e 's/^####/##/')
# description="${description//'%'/'%25'}"
# description="${description//$'\n'/'%0A'}"
# description="${description//$'\r'/'%0D'}"
# echo "::set-output name=body::${description}"
# env:
# GITHUB_AUTH: ${{ secrets.LERNA_CHANGELOG_GITHUB_AUTH }}
# - uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: ${{steps.validate.outputs.version}}
# release_name: Version ${{steps.validate.outputs.version}}
# body: ${{steps.changelog.outputs.body}}
# draft: false
# prerelease: false
slack:
name: Slack Notification
runs-on: ubuntu-latest
needs: [skip, dockle, trivy, publish]
steps:
- name: Slack Notification
uses: 8398a7/action-slack@v2
if: always()
with:
status: ${{ job.status }}
author_name: ProjectPrimera/ongeki-score
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TEST }}