forked from equinor/aware
-
Notifications
You must be signed in to change notification settings - Fork 1
162 lines (138 loc) · 5.01 KB
/
docker-web-publish.yaml
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
name: Push web to GHCR
on:
workflow_dispatch:
push:
branches:
- master
paths:
- web/**
- "!*.md"
pull_request:
branches:
- master
paths:
- web/**
- "!*.md"
env:
REGISTRY: ghcr.io
REPO_NAME: ${{ github.repository }}
IMAGE_SUFFIX: "/web" # change to suit your image name
BUILD_CONTEXT: "./web" # change me to fit your image path
DOCKERFILE_PATH: "default" # change me if needed
ARTIFACT: dummyweb
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate required output vars
id: env
shell: pwsh
run: |
$env:tag = (Get-Date -Format dd-MM-yyyy) + "." + ${{ github.run_number }}
Write-Host "::set-output name=tag::$($env:tag)"
if ("${{ env.DOCKERFILE_PATH }}" -eq "default")
{
$env:dockerfilePath = "${{ env.BUILD_CONTEXT}}/Dockerfile"
}
else
{
$env:dockerfilePath = "${{ env.DOCKERFILE_PATH }}"
}
Write-Host "::set-output name=DOCKERFILE_PATH::$($env:dockerfilePath)"
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.REPO_NAME }}${{ env.IMAGE_SUFFIX }}
tags: |
type=sha,format=long
type=raw,value=${{ steps.env.outputs.tag }}
type=raw,value=latest
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: ${{ env.BUILD_CONTEXT }}
file: ${{ steps.env.outputs.DOCKERFILE_PATH }}
push: ${{ github.event_name != 'pull_request' }}
load: ${{ github.event_name == 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
#outputs: type=docker,dest=/tmp/web.tar
#- run: docker load -i /tmp/web.tar
# - name: Container image scan
# if: github.event_name == 'pull_request'
# env:
# # See https://github.com/Azure/container-scan/issues/146
# DOCKLE_HOST: "unix:///var/run/docker.sock"
# id: scan
# uses: Azure/[email protected]
# with:
# image-name: ${{ env.REGISTRY }}/${{ env.REPO_NAME }}${{ env.IMAGE_SUFFIX }}:${{ steps.env.outputs.tag }}
# severity-threshold: "CRITICAL"
# - name: Run hadolint
# uses: hadolint/[email protected]
# with:
# dockerfile: ${{ steps.env.outputs.DOCKERFILE_PATH }}
# format: sarif
# output-file: hadolint-results.sarif
# no-fail: true
# - name: Upload analysis results to GitHub
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: hadolint-results.sarif
# - uses: actions/setup-dotnet@v3
# with:
# dotnet-version: |
# 6.0.x
# # Run Dockerfile and Docker image analyzers
# - name: Run Microsoft Security DevOps Analysis
# uses: microsoft/security-devops-action@preview
# env:
# #terrascan_SkipRules: ""
# GDN_TRIVY_ACTION: "image"
# GDN_TRIVY_IMAGEPATH: /tmp/web.tar
# id: msdo
# # Upload alerts to the Security tab
# - name: Upload alerts to Security tab
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: ${{ steps.msdo.outputs.sarifFile }}
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
# - name: Install cosign
# if: github.event_name != 'pull_request'
# uses: sigstore/[email protected]
# - name: Sign the images with GitHub OIDC Token
# if: ${{ github.event_name != 'pull_request' }}
# env:
# DIGEST: ${{ steps.build-and-push.outputs.digest }}
# TAGS: ${{ steps.meta.outputs.tags }}
# run: cosign sign --yes "${TAGS}@${DIGEST}"