forked from 123Haynes/fritzbox_exporter
-
Notifications
You must be signed in to change notification settings - Fork 45
167 lines (137 loc) · 4.61 KB
/
container.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
name: Container
on:
push:
# Publish `main` as Docker `latest` image.
branches:
- main
- master
# Publish `v1.2.3` tags as releases.
tags:
- '**' # All tags kick off a new container build Save history ad 5.0.x etc
# Run tests for any PRs.
pull_request:
env:
BUILD_PLATFORM: |
linux/arm/v6
linux/arm/v7
linux/arm64
linux/amd64
# Enable Docker Buildkit
DOCKER_BUILDKIT: 1
IMAGE_NAME: fritzbox_exporter
jobs:
lint:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint Dockerfile
uses: hadolint/[email protected]
with:
dockerfile: Dockerfile
prepare:
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: lint
# Map a step output to a job output
outputs:
DOCKER_REPOSITORY: ${{ steps.tag_image.outputs.DOCKER_REPOSITORY }}
DOCKER_TAG: ${{ steps.tag_image.outputs.DOCKER_TAG }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Tag Image
id: tag_image
run: |
DOCKER_REPOSITORY=ghcr.io/${{ github.repository }}
# Change all uppercase to lowercase
DOCKER_REPOSITORY=$(echo $DOCKER_REPOSITORY | tr '[A-Z]' '[a-z]')
DOCKER_TAG=${{ github.ref_name }}
# Use Docker `latest` tag convention
[ "$DOCKER_TAG" == "master" ] && DOCKER_TAG=latest
[ "$DOCKER_TAG" == "main" ] && DOCKER_TAG=latest
echo DOCKER_REPOSITORY=$DOCKER_REPOSITORY
echo DOCKER_TAG=$DOCKER_TAG
echo "DOCKER_REPOSITORY=${DOCKER_REPOSITORY}" >> $GITHUB_OUTPUT
echo "DOCKER_TAG=${DOCKER_TAG}" >> $GITHUB_OUTPUT
# Build and push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
build:
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: [prepare]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Build Image
uses: docker/build-push-action@v5
with:
build-args: REPO=${{ github.repository }}
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
file: Dockerfile
platforms: ${{ env.BUILD_PLATFORM }}
push: false
# Build and push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: [prepare, build]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build Runtime Image and Push
uses: docker/build-push-action@v5
with:
build-args: REPO=${{ github.repository }}
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
file: Dockerfile
platforms: ${{ env.BUILD_PLATFORM }}
push: true
tags: |
${{ needs.prepare.outputs.DOCKER_REPOSITORY }}:${{ needs.prepare.outputs.DOCKER_TAG }}
${{ needs.prepare.outputs.DOCKER_REPOSITORY }}:${{ github.sha }}
target: runtime-image
- name: Inspect image
if: success()
run: |
docker buildx imagetools inspect ${{ needs.prepare.outputs.DOCKER_REPOSITORY }}:${{ needs.prepare.outputs.DOCKER_TAG }}
docker buildx imagetools inspect ${{ needs.prepare.outputs.DOCKER_REPOSITORY }}:${{ github.sha }}
test:
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: [prepare, push]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: "${{ needs.prepare.outputs.DOCKER_REPOSITORY }}:${{ github.sha }}"
format: 'sarif'
output: 'trivy-results.sarif'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'MEDIUM,HIGH,CRITICAL'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'