-
Notifications
You must be signed in to change notification settings - Fork 1
166 lines (151 loc) · 6.17 KB
/
cicd.yaml
File metadata and controls
166 lines (151 loc) · 6.17 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
157
158
159
160
161
162
163
164
165
166
#
name: Create and publish a Docker image
# Configures this workflow to run every time a change is pushed to the branch called `release`.
on:
workflow_dispatch:
push:
branches:
- 'main'
- 'releases/**'
tags:
- 'v*'
pull_request:
branches:
- 'main'
env:
# Sets the Docker image tag to use for the image built in this workflow.
features_dir: src/features
base_dir: src/devcontainers
context: .devcontainer
workspace_folder: .
readme: README.md
registry: ghcr.io
dockerfile: Dockerfile
server: https://github.com
org: NHSDigital
repository: nhs-notify-devcontainers
vendor: NHS England
node_version: 24
temp_dockerfile: /tmp/Dockerfile.source
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
deploy-nhs-notify-feature:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
permissions:
packages: write
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
src:
- '${{ env.features_dir }}/**'
- if: steps.changes.outputs.src == 'true' || startsWith(github.ref, 'refs/tags/v')
name: "Publish Features"
uses: devcontainers/action@v1
with:
publish-features: "true"
base-path-to-features: "./${{ env.features_dir }}"
generate-docs: "false"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-and-push-image:
runs-on: ubuntu-latest
needs: [deploy-nhs-notify-feature]
strategy:
fail-fast: false
max-parallel: 1
matrix:
include:
- container_name: base
image: nhsdigital/nhs-notify-devcontainer-base
title: NHS Notifiy Devcontainer Base Image
description: Base development container for NHS Notify projects
- container_name: default
image: nhsdigital/nhs-notify-devcontainer-default
title: NHS Notifiy Devcontainer Default Image
description: Default development container for NHS Notify projects
- container_name: loaded
image: nhsdigital/nhs-notify-devcontainer-loaded
title: NHS Notifiy Devcontainer Loaded Image
description: Loaded development container for NHS Notify projects
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v5
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
src:
- '${{env.base_dir}}/${{ matrix.container_name }}/**'
- if: steps.changes.outputs.src == 'true' || startsWith(github.ref, 'refs/tags/v')
name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.registry }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- if: steps.changes.outputs.src == 'true' || startsWith(github.ref, 'refs/tags/v')
uses: actions/setup-node@v6
with:
node-version: ${{ env.node_version }}
- if: steps.changes.outputs.src == 'true' || startsWith(github.ref, 'refs/tags/v')
name: Build
working-directory: ${{env.base_dir}}/${{ matrix.container_name }}
run: |
make build IMAGE_NAME=${{ env.registry }}/${{ matrix.image }} WORKSPACE_FOLDER=${{ env.workspace_folder }}
- if: steps.changes.outputs.src == 'true' || startsWith(github.ref, 'refs/tags/v')
name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.registry }}/${{ matrix.image }}
flavor: |
latest=auto
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=schedule
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=ref,event=pr
type=sha
labels: |
org.opencontainers.image.title= ${{ matrix.title }}
org.opencontainers.image.description=${{ matrix.description }}
org.opencontainers.image.vendor=${{ env.vendor }}
org.opencontainers.image.url=${{ env.server }}/${{ env.org }}/${{ env.repository }}/blob/main/${{ env.base_dir }}/${{matrix.container_name}}/${{ env.readme }}
org.opencontainers.image.source=${{ env.server }}/${{ env.org }}/${{ env.repository }}/tree/main/${{ env.base_dir }}/${{matrix.container_name}}/
- if: steps.changes.outputs.src == 'true' || startsWith(github.ref, 'refs/tags/v')
name: create temp dockerfile source
run: echo 'FROM ${{ env.registry }}/${{ matrix.image }}' > ${{ env.temp_dockerfile }}
- if: steps.changes.outputs.src == 'true' || startsWith(github.ref, 'refs/tags/v')
name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: ${{ env.temp_dockerfile }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- if: steps.changes.outputs.src == 'true' || startsWith(github.ref, 'refs/tags/v')
name: Generate artifact attestation
uses: actions/attest-build-provenance@v3
with:
subject-name: ${{ env.registry }}/${{ matrix.image }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: false