Tag new versions in git #35
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Container Image | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
env: | |
ARTIFACT_REGISTRY: europe-north1-docker.pkg.dev | |
ARTIFACT_REPO: nais-io/nais/images | |
SERVICE_ACCOUNT: [email protected] | |
jobs: | |
meta: | |
name: Metadata | |
runs-on: ubuntu-latest | |
outputs: | |
"version": ${{ steps.version.outputs.version }} | |
"name": ${{ steps.name.outputs.name }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- id: version | |
run: echo "version=$(date +'%Y%m%d')-$(git rev-parse --short HEAD)" >> ${GITHUB_OUTPUT} | |
- id: name | |
run: echo "name=${{ github.event.repository.name }}" >> ${GITHUB_OUTPUT} | |
build_and_push: | |
name: Build and push | |
permissions: | |
contents: read | |
id-token: write | |
runs-on: ubuntu-latest-16-cores | |
needs: meta | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- id: "auth" | |
if: github.actor != 'dependabot[bot]' | |
name: "Authenticate to Google Cloud" | |
uses: google-github-actions/[email protected] | |
with: | |
workload_identity_provider: ${{ secrets.NAIS_IO_WORKLOAD_IDENTITY_PROVIDER }} | |
service_account: ${{ env.SERVICE_ACCOUNT }} | |
token_format: "access_token" | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to registry | |
if: github.actor != 'dependabot[bot]' | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.ARTIFACT_REGISTRY }}/${{ env.ARTIFACT_REPO }} | |
username: "oauth2accesstoken" | |
password: "${{ steps.auth.outputs.access_token }}" | |
- name: Docker meta | |
id: metadata | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.ARTIFACT_REGISTRY }}/${{ env.ARTIFACT_REPO }}/${{ needs.meta.outputs.name }} | |
# Docker tags based on the following events/attributes | |
tags: | | |
type=schedule | |
type=ref,event=branch | |
type=sha | |
type=raw,value=${{ needs.meta.outputs.version }} | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: Dockerfile | |
push: ${{ github.ref == 'refs/heads/main' }} | |
tags: ${{ steps.metadata.outputs.tags }} | |
labels: ${{ steps.metadata.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |