-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (115 loc) · 4.94 KB
/
Copy pathoci-ci.yaml
File metadata and controls
115 lines (115 loc) · 4.94 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
name: OCI Image CI
on:
workflow_call:
inputs:
artifact_registry_location:
type: string
default: "europe"
description: Artifact registry region name (e.g. "europe", "europe-north1").
environment:
type: string
description: The environment name to use. If set variables will be loaded from env.$(ENVIRONMENT)
publish:
type: boolean
default: false
description: Set to true to publish the OCI Image produced by this workflow.
docker-compose-service:
type: string
description: The docker compose service providing the CI executables validate, build and publish
workload_identity_provider:
type: string
service_account:
type: string
xdg_cache_hash:
type: string
default: ""
description: The path argument for the GitHub Actions function hashFiles.
tags:
type: string
default: ""
description: The tags (separated by space) to use for the image.
secrets:
REVIEWBOT_GITHUB_TOKEN:
required: true
outputs:
image:
value: ${{ jobs.oci-ci.outputs.image }}
description: The full OCI Image reference.
image_tag:
value: ${{ jobs.oci-ci.outputs.image_tag }}
description: The OCI Image tag.
defaults:
run:
shell: bash
env:
XDG_CACHE_HOME: ${{ github.workspace }}/.cache/xdg
jobs:
oci-ci:
name: OCI Image CI
runs-on: ubuntu-24.04
permissions:
contents: read
id-token: write
packages: read
outputs:
image: ${{ steps.metadata.outputs.image }}
image_tag: ${{ steps.metadata.outputs.image_tag }}
image_digest: ${{ steps.metadata.outputs.image_digest }}
steps:
- uses: actions/checkout@v6
- name: Set up QEMU
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
- name: Cache xdg
if: ${{ inputs.xdg_cache_hash != '' }}
uses: actions/cache@v5
with:
path: ${{ env.XDG_CACHE_HOME }}
key: xdg-${{ github.repository }}-${{ github.job }}-${{ inputs.xdg_cache_hash }}
restore-keys: |
xdg-${{ github.repository }}-${{ github.job }}-${{ inputs.xdg_cache_hash }}
xdg-${{ github.repository }}-${{ github.job }}-
- name: Login to GitHub Container Registry
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Configure access to internal and private GitHub repos
run: git config --global url."https://${{ secrets.REVIEWBOT_GITHUB_TOKEN }}:x-oauth-basic@github.com/coopnorge".insteadOf "https://github.com/coopnorge"
- name: Build devtools
run: docker compose build ${{ inputs.docker-compose-service }}
- name: Validate
run: docker compose run --rm ${{ inputs.docker-compose-service }} validate VERBOSE=all ENVIRONMENT=${{ inputs.environment }}
- name: Build
run: docker compose run --rm ${{ inputs.docker-compose-service }} build VERBOSE=all ENVIRONMENT=${{ inputs.environment }} OCI_TAG_SUFFIX_USER="${{ inputs.tags }}"
- name: Autenticate with GCP
if: ${{ inputs.publish }}
uses: "google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093" # v3.0.0
with:
workload_identity_provider: ${{ inputs.workload_identity_provider }}
service_account: ${{ inputs.service_account }}
create_credentials_file: true
- name: Configure Google Cloud Artifact Registry for Docker
if: ${{ inputs.publish }}
run: gcloud auth print-access-token | docker login https://${{ inputs.artifact_registry_location }}-docker.pkg.dev -u oauth2accesstoken --password-stdin
- name: Publish with Tag
if: ${{ inputs.publish && inputs.tags != ''}}
run: docker compose run --rm ${{ inputs.docker-compose-service }} publish VERBOSE=all ENVIRONMENT=${{ inputs.environment }} OCI_TAG_SUFFIX_USER="${{ inputs.tags }}"
- name: Publish
if: ${{ inputs.publish }}
run: docker compose run --rm ${{ inputs.docker-compose-service }} publish VERBOSE=all ENVIRONMENT=${{ inputs.environment }}
- name: Output Image Metadata
id: metadata
run: |
IMAGE_NAME=$(docker compose run --rm ${{ inputs.docker-compose-service }} yq --output-format=yaml '.["image.name"]' oci-metadata.json)
IMAGE_NAME=${IMAGE_NAME##*,}
TAG=${IMAGE_NAME##*:}
echo "image=${IMAGE_NAME}" >> $GITHUB_OUTPUT
echo "image_tag=${TAG}" >> $GITHUB_OUTPUT
- name: Fix cache permissions
if: ${{ inputs.xdg_cache_hash != '' }}
run: |
sudo chown -R $(id -u):$(id -g) "${XDG_CACHE_HOME}"
sudo chmod -R ugo+rX "${XDG_CACHE_HOME}"