-
Notifications
You must be signed in to change notification settings - Fork 27
156 lines (153 loc) · 5.75 KB
/
Copy pathcontainer-build-apache.yaml
File metadata and controls
156 lines (153 loc) · 5.75 KB
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
---
name: Create and publish a apache image
permissions:
actions: read
contents: read
id-token: write
packages: write
pull-requests: write
security-events: write
on:
pull_request:
paths:
- .github/workflows/container-build-apache.yaml
- ContainerFiles/apache
schedule:
- cron: '0 0 * * 0' # Run Weekly at midnight UTC
workflow_dispatch:
inputs:
apache-mod-wsgi-version:
description: 'Version of Apache mod_wsgi to use'
required: true
default: "master"
type: choice
options:
- "master"
- "5.0.2"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/apache
# NOTE(cloudnull): This is used to parse the workflow_dispatch inputs, sadly the inputs are not available in the
# workflow_dispatch event, so they're being stored in the environment variables. This is a
# workaround until there's a better way to handle this.
mod_wsgi: >
["5.0.2"]
jobs:
init:
runs-on: ubuntu-latest
outputs:
apache-mod-wsgi-version: ${{ steps.generate-matrix.outputs.mod_wsgi }}
steps:
- name: generate-matrix
id: generate-matrix
run: |
if [ "${{ github.event_name == 'workflow_dispatch' }}" = "true" ]; then
mod_wsgi="$(echo '${{ github.event.inputs.apache-mod-wsgi-version }}' | jq -R '[select(length>0)]' | jq -c '.')"
fi
echo "mod_wsgi=${mod_wsgi:-${{ env.mod_wsgi }}}" >> $GITHUB_OUTPUT
build-and-push-image:
needs:
- init
strategy:
matrix:
apache-mod-wsgi-version: ${{ fromJSON(needs.init.outputs.apache-mod-wsgi-version) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Dynamically set MY_DATE environment variable
run: echo "MY_DATE=$(date +%s)" >> $GITHUB_ENV
- name: Normalize image repository name
run: echo "IMAGE_NAME=$(echo "${IMAGE_NAME}" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Dynamically set environment variables
run: |
VERSION=$(echo -n "${{ matrix.apache-mod-wsgi-version }}" | awk -F'/' '{($2=="" ? x=$1 : x=$2); print x}')
echo "OS_VERSION_PARSE=${VERSION}" >> $GITHUB_ENV
NAME=$(echo -n "${{ env.IMAGE_NAME }}" | awk -F'/' '{print $NF}')
echo "CATEGORY_NAME=${VERSION}-${NAME}" >> $GITHUB_ENV
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ContainerFiles/apache
push: false
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ env.IMAGE_NAME }}:local
labels: ${{ steps.meta.outputs.labels }}
build-args: |
MOD_WSGI_VERSION=${{ matrix.apache-mod-wsgi-version }}
CACHEBUST=${{ github.sha }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@0.35.0 # using latest trivy scanner
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
with:
image-ref: '${{ env.IMAGE_NAME }}:local'
format: 'sarif'
output: 'trivy-results.sarif'
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results to GitHub Security tab
continue-on-error: true
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
category: "${{ env.CATEGORY_NAME }}"
- name: Run Trivy scanner
uses: aquasecurity/trivy-action@0.35.0 # using latest trivy scanner
if: ${{ github.event_name == 'pull_request' }}
with:
image-ref: '${{ env.IMAGE_NAME }}:local'
output: trivy.txt
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
- name: Create trivy output file in markdown format
if: ${{ github.event_name == 'pull_request' }}
run: |
if [[ -s trivy.txt ]]; then
echo "### Security Output" > trivy-output.txt
echo '```terraform' >> trivy-output.txt
cat trivy.txt >> trivy-output.txt
echo '```' >> trivy-output.txt
fi
- name: Publish Trivy Output to Summary
if: ${{ github.event_name == 'pull_request' }}
run: |
if [[ -s trivy-output.txt ]]; then
{
cat trivy-output.txt
} >> $GITHUB_STEP_SUMMARY
fi
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ContainerFiles/apache
push: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.MY_DATE }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
MOD_WSGI_VERSION=${{ matrix.apache-mod-wsgi-version }}
CACHEBUST=${{ github.sha }}