-
-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (99 loc) · 3.36 KB
/
publish.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
name: Publish
on:
schedule:
- cron: "0 0 1 * *"
push:
branches: [master]
pull_request:
branches: [master]
env:
REGISTRY: docker.io
G_REGISTRY: ghcr.io
IMAGE_NAME: hatamiarash7/fake-smtp
jobs:
Test:
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ env.IMAGE_NAME }}:${{ github.sha }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: "${{ env.IMAGE_NAME }}:${{ github.sha }}"
exit-code: "0"
ignore-unfixed: true
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
format: "template"
template: "@/contrib/sarif.tpl"
output: "trivy-results.sarif"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: "trivy-results.sarif"
Github:
needs: Test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
with:
ref: master
- id: github-image
uses: ASzc/change-string-case-action@v5
with:
string: ${{ env.G_REGISTRY }}/${{ github.repository }}:latest
- name: Get Current Date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Build image
run: |
docker build -t ${{ steps.github-image.outputs.lowercase }} --build-arg DATE_CREATED=${{ steps.date.outputs.date }} .
- name: Log into registry ${{ env.G_REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2.2.0
with:
registry: ${{ env.G_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to ${{ env.G_REGISTRY }}
if: github.event_name != 'pull_request'
run: |
docker push ${{ steps.github-image.outputs.lowercase }}
Dockerhub:
needs: Test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
with:
ref: master
- id: dockerhub-image
uses: ASzc/change-string-case-action@v5
with:
string: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name: Get Current Date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Build image
run: |
docker build -t ${{ steps.dockerhub-image.outputs.lowercase }} --build-arg DATE_CREATED=${{ steps.date.outputs.date }} .
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2.2.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push to ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
run: |
docker push ${{ steps.dockerhub-image.outputs.lowercase }}