-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (119 loc) · 4.26 KB
/
Copy pathbuild-release.yaml
File metadata and controls
135 lines (119 loc) · 4.26 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
name: Docker Build and Push
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Enable manual trigger from Actions tab
workflow_dispatch:
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
IMAGE_NAME: mywebapp
PLATFORMS: linux/amd64,linux/arm64
# TARGET_REPO: prabhjotbawa/helm-charts
# TARGET_BRANCH: main
# TARGET_FILE_PATH: charts/webapp/values.yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
load: true
tags: ${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
comprehensive-scan:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Cache Trivy vulnerability database
uses: actions/cache@v4
with:
path: .trivycache/
key: ${{ runner.os }}-trivy-${{ github.sha }}
restore-keys: |
${{ runner.os }}-trivy-
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@7b7aa264d83dc58691451798b4d117d53d21edfe
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
image-ref: ${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
format: 'template'
template: '@/contrib/sarif.tpl'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
cache-dir: .trivycache/
skip-db-update: ${{ github.event_name != 'schedule' }}
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
push:
needs: build
runs-on: ubuntu-latest
# Only run this job if we're on the main branch and not in a pull request
if: github.event_name != 'pull_request'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ env.PLATFORMS }}
push: true
tags: |
${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
# OPTIONAL CODE TO UPDATE HELM CHART TAG
# - name: Checkout target repository
# uses: actions/checkout@v4
# with:
# repository: ${{ env.TARGET_REPO }}
# token: ${{ secrets.PAT_TOKEN }} # Need a Personal Access Token with repo access
# path: target-repo
#
# - name: Update image tag
# run: |
# cd target-repo
# ls -l
# # Update the image tag in the target file
# # This example assumes YAML format - adjust the command based on your file format
# yq e ".image.django.tag = \"${{ github.sha }}\"" -i ${{ env.TARGET_FILE_PATH }}
#
# - name: Commit and push changes
# run: |
# cd target-repo
# git config user.name "GitHub Actions"
# git config user.email "actions@github.com"
# git add ${{ env.TARGET_FILE_PATH }}
# git commit -m "Update image tag to ${{ github.sha }}"
# git push