Skip to content

Commit d457f3b

Browse files
authored
First pass at a build Docker image gh action (#22)
1 parent 04eaa4e commit d457f3b

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# This workflow will build and push a signed Docker image
2+
3+
name: Build and sign image
4+
5+
on:
6+
# THIS BLOCK IS FOR TESTING
7+
branch_protection_rule:
8+
types:
9+
- created
10+
11+
# THIS BLOCK IS THE ACTUAL DESIRED EVENT TRIGGER
12+
# pull_request:
13+
# branches:
14+
# - "*" # Run on all branches
15+
# types:
16+
# - closed ## This needs to be uncommented after testing
17+
18+
env:
19+
REGISTRY: hub.docker.com
20+
IMAGE_NAME: "ciroque/nginx-k8s-loadbalancer" # ${{ github.repository }}
21+
22+
jobs:
23+
build_and_sign_image:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
packages: write
28+
id-token: write
29+
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v3
33+
34+
- name: Install cosign
35+
if: github.event_name != 'pull_request'
36+
uses: sigstore/cosign-installer@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0
37+
with:
38+
cosign-release: 'v1.13.1'
39+
40+
- name: Docker Buildx
41+
uses: docker/setup-buildx-action@4b4e9c3e2d4531116a6f8ba8e71fc6e2cb6e6c8c # v2.5.0
42+
43+
- name: Log into registry ${{ env.REGISTRY }} for ${{ github.actor }}
44+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
45+
with:
46+
registry: ${{ env.REGISTRY }}
47+
username: ${{ github.actor }}
48+
password: ${{ secrets.DOCKER_HUB_TOKEN }}
49+
50+
- name: Build Docker Image
51+
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
52+
with:
53+
context: .
54+
file: ./Dockerfile
55+
push: true
56+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
57+
58+
- name: Run Trivy vulnerability scanner
59+
uses: aquasecurity/trivy-action@1f0aa582c8c8f5f7639610d6d38baddfea4fdcee # 0.9.2
60+
continue-on-error: true
61+
with:
62+
image-ref: docker.io/${{ inputs.image }}:${{ steps.meta.outputs.version }}
63+
format: 'sarif'
64+
output: 'trivy-results-${{ inputs.image }}.sarif'
65+
ignore-unfixed: 'true'
66+
67+
- name: Upload Trivy scan results to GitHub Security tab
68+
uses: github/codeql-action/upload-sarif@16964e90ba004cdf0cd845b866b5df21038b7723 # v2.2.6
69+
continue-on-error: true
70+
with:
71+
sarif_file: 'trivy-results-${{ inputs.image }}.sarif'

.github/workflows/go.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: Go
55

66
on:
77
push:
8-
branches: [ "main" ]
8+
branches: [ "main", "*" ]
99
pull_request:
1010
branches: [ "main" ]
1111

0 commit comments

Comments
 (0)