-
Notifications
You must be signed in to change notification settings - Fork 2
94 lines (78 loc) · 2.24 KB
/
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
name: Docker
on:
push:
branches:
- master
paths:
- "Dockerfile"
- ".github/workflows/docker.yml"
pull_request:
branches:
- master
paths:
- "Dockerfile"
- ".github/workflows/docker.yml"
env:
IMAGE_NAME: hatamiarash7/webhook
GITHUB_IMAGE_NAME: ${{ github.repository }}/webhook
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Cancel previous workflow
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v3
- name: Build image
run: docker build -t test .
- name: Trivy
uses: aquasecurity/trivy-action@master
with:
image-ref: test
format: "template"
template: "@/contrib/sarif.tpl"
output: "trivy-results.sarif"
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: "trivy-results.sarif"
- name: Lint Docker files
uses: hadolint/hadolint-action@v2.1.0
with:
verbose: true
ignore: "DL3008,DL3025"
failure-threshold: "error"
push:
name: Deploy
needs: test
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create image name
id: github-image
uses: ASzc/change-string-case-action@v4
with:
string: ghcr.io/${{ env.GITHUB_IMAGE_NAME }}
- name: Get Current Date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Build image
run: >
docker build
-t ${{ env.IMAGE_NAME }}
-t ${{ steps.github-image.outputs.lowercase }}
--build-arg DATE_CREATED=${{ steps.date.outputs.date }}
-f Dockerfile
.
- name: Push to Dockerhub
run: |
docker login -u hatamiarash7 -p "${{ secrets.DOCKERHUB_TOKEN }}"
docker push ${{ env.IMAGE_NAME }}
- name: Push to Github
run: |
docker login -u hatamiarash7 -p "${{ secrets.GB_TOKEN }}" ghcr.io
docker push ${{ steps.github-image.outputs.lowercase }}