Skip to content

Commit

Permalink
Update docker-publish.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
egagli authored Jan 8, 2025
1 parent 047c8f0 commit 20e04a3
Showing 1 changed file with 15 additions and 36 deletions.
51 changes: 15 additions & 36 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,44 @@
# .github/workflows/docker-publish.yml
name: Build and Publish Docker Image
name: Create and publish Docker image

on:
push:
branches: [ main ]
paths:
- 'environment.yml'
- 'apt.txt'
- 'Dockerfile'
workflow_dispatch:
branches: ['main']
pull_request:
branches: ['main']

env:
REGISTRY: ghcr.io
ORGANIZATION: UW-GDA
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push:
build-and-push-image:
runs-on: ubuntu-latest
# Ensure the job runs within the organization context
if: github.repository_owner == 'UW-GDA'

permissions:
contents: read
packages: write
attestations: write
id-token: write


steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to GitHub Container Registry

- name: Log in to the Container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.TOKEN_GITHUB }}

- name: Extract Docker metadata
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,format=long
type=ref,event=branch
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
push: true
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

0 comments on commit 20e04a3

Please sign in to comment.