-
Notifications
You must be signed in to change notification settings - Fork 11
124 lines (107 loc) · 4.12 KB
/
build.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
name: Build Image
on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '30 2 * * *'
env:
PACKAGES: "apk-tools ca-certificates ssl_client"
ROOTFS_HASH: "91ceb95b020260832417b01e45ce02c3a250c4527835d1bdf486bf44f80287dc"
ROOTFS_VERSION: "v0.7.0"
POST_INSTALL: "./post-install.sh"
jobs:
build-image:
runs-on: ubuntu-latest
name: Build Image
strategy:
matrix:
version: ["3.18", "3.17", "3.16", "3.15"]
permissions:
contents: read
packages: write
security-events: write
env:
BUILD_TAR: "/tmp/docker-${{ matrix.version }}/alpine-rootfs.tar.gz"
DOCKER_IMAGE: "ghcr.io/${{ github.repository_owner }}/alpine"
DOCKER_ROOT: "/tmp/docker-${{ matrix.version }}"
DOCKER_TAG: ${{ matrix.version }}
MKROOTFS: "/tmp/alpine-make-rootfs-${{ matrix.version }}"
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v3
- name: Fetch MakeRootFS Util
id: fetch-makerootfs
run: |
wget https://raw.githubusercontent.com/alpinelinux/alpine-make-rootfs/${{ env.ROOTFS_VERSION }}/alpine-make-rootfs -O "${{ env.MKROOTFS }}"
echo "${{ env.ROOTFS_HASH }} ${{ env.MKROOTFS }}" | sha256sum -c -
chmod +x ${{ env.MKROOTFS }}
- name: Build Filesystem
id: build-fs
run: |
mkdir ${{ env.DOCKER_ROOT }}
sudo ${{ env.MKROOTFS }} --mirror-uri https://dl-cdn.alpinelinux.org/alpine \
--branch "v${{ matrix.version }}" \
--packages "${{ env.PACKAGES }}" \
--script-chroot \
"${{ env.BUILD_TAR }}" \
"${{ env.POST_INSTALL }}"
- name: Prepare Dockerfile
id: prepare-dockerfile
run: |
cat <<DOCKERFILE > "${{ env.DOCKER_ROOT }}/Dockerfile"
FROM scratch
ADD $(basename ${{ env.BUILD_TAR }}) /
CMD ["/bin/sh"]
DOCKERFILE
- name: Extract Docker Metadata
id: meta
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96
with:
images:
${{ env.DOCKER_IMAGE }}
tags:
${{ env.DOCKER_TAG }}
- name: Build Docker Image
id: build-image
uses: docker/build-push-action@v3
with:
context: ${{ env.DOCKER_ROOT }}
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Run Trivy
id: trivy
if: ${{ github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'schedule') }}
uses: aquasecurity/trivy-action@9ab158e8597f3b310480b9a69402b419bc03dbd5 # v0.8.0
with:
image-ref: "${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}"
format: 'sarif'
output: 'trivy-results-${{ matrix.version }}.sarif'
- name: Run Trivy (PR only)
id: trivy-pr
if: ${{ github.ref != 'refs/heads/main' || (github.event_name != 'push' && github.event_name != 'schedule') }}
uses: aquasecurity/trivy-action@9ab158e8597f3b310480b9a69402b419bc03dbd5 # v0.8.0
with:
image-ref: "${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}"
format: 'table'
severity: 'MEDIUM,HIGH,CRITICAL'
- name: Upload Trivy Results to GitHub Security tab
if: ${{ github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'schedule') }}
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results-${{ matrix.version }}.sarif'
- name: Login to Github Container Registry
if: ${{ github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'schedule') }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Image
if: ${{ github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'schedule') }}
run: docker push "${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}"