Changes action to use github variables.
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 2m44s
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 2m44s
This commit is contained in:
parent
09b8e093ec
commit
67a422ffb4
2 changed files with 35 additions and 37 deletions
|
@ -1,73 +1,69 @@
|
||||||
name: Build and Push Docker Image
|
name: Build and Push Docker Image
|
||||||
|
|
||||||
# Controls when the workflow will run
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main # Run on pushes to the main branch
|
- main # Adjust if your main branch is different
|
||||||
tags:
|
tags:
|
||||||
- 'v*.*.*' # Run on pushes of tags like v1.0.0, v1.2.3 etc.
|
- 'v*.*.*' # Trigger on version tags
|
||||||
|
|
||||||
# Environment variables available to all jobs and steps in the workflow
|
|
||||||
env:
|
env:
|
||||||
# Use the Forgejo instance URL directly from the context
|
REGISTRY: git.cmzi.uk
|
||||||
REGISTRY: ${{ forgejo.instance }}
|
|
||||||
# Construct the base image name using owner and repo name
|
# Use 'github' context variables as fallbacks for repo owner and name
|
||||||
IMAGE_BASE_NAME: ${{ forgejo.repository_owner }}/${{ forgejo.repository }}
|
IMAGE_BASE_NAME: ${{ github.repository_owner }}/${{ github.repository }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
build-and-push:
|
||||||
runs-on: docker-cli # Or specify your preferred runner type that has Docker
|
runs-on: ubuntu-latest # Or your preferred runner with Docker
|
||||||
permissions: # Needed for the action to interact with the registry
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write # Required to push to the container registry
|
packages: write # Still required for pushing to the registry
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Fetches all history for all tags and branches - needed for metadata action
|
fetch-depth: 0 # Recommended for metadata action
|
||||||
|
|
||||||
# Optional: Set up QEMU for multi-platform builds (if needed)
|
|
||||||
# - name: Set up QEMU
|
|
||||||
# uses: docker/setup-qemu-action@v3
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
id: buildx # Step ID for referencing outputs
|
id: buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Log in to Forgejo Container Registry
|
- name: Log in to Forgejo Container Registry
|
||||||
# Uses the automatically generated FORGEJO_TOKEN for authentication
|
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ env.REGISTRY }} # Use the registry URL defined above
|
||||||
username: ${{ forgejo.actor }} # The user/actor that triggered the workflow
|
# Use 'github.actor' as a fallback for the username context
|
||||||
password: ${{ secrets.FORGEJO_TOKEN }} # Built-in secret provided by Forgejo Actions
|
username: ${{ github.actor }}
|
||||||
|
# Use the Forgejo-specific token - this SHOULD still work if Actions are enabled
|
||||||
|
password: ${{ secrets.FORGEJO_TOKEN }}
|
||||||
|
|
||||||
- name: Extract metadata (tags, labels) for Docker
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
id: meta # Step ID for referencing outputs
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
|
# Construct the full image name using the defined REGISTRY and IMAGE_BASE_NAME
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_BASE_NAME }}
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_BASE_NAME }}
|
||||||
# Defines tagging strategy based on the event that triggered the workflow
|
|
||||||
tags: |
|
tags: |
|
||||||
# tag latest for default branch (e.g., main)
|
# Use 'github.ref' for branch/tag detection
|
||||||
type=raw,value=latest,enable=${{ forgejo.ref == format('refs/heads/{0}', 'main') }}
|
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} # Adjust 'main' if needed
|
||||||
# tag with the git branch name if it's a branch push
|
|
||||||
type=ref,event=branch
|
type=ref,event=branch
|
||||||
# tag with the git tag name if it's a tag push (e.g., v1.0.0)
|
|
||||||
type=ref,event=tag
|
type=ref,event=tag
|
||||||
# tag with the short git SHA
|
type=sha,format=short # Tag with short Git SHA
|
||||||
type=sha,format=short
|
# Add standard OCI labels using github context
|
||||||
|
labels: |
|
||||||
|
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
||||||
|
org.opencontainers.image.revision=${{ github.sha }}
|
||||||
|
org.opencontainers.image.ref.name=${{ github.ref_name }}
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: . # Build context is the repository root
|
context: .
|
||||||
file: ./Dockerfile # Path to your Dockerfile (default)
|
file: ./Dockerfile
|
||||||
# platforms: linux/amd64,linux/arm64 # Uncomment for multi-platform builds (requires QEMU step)
|
push: true
|
||||||
push: true # Push the image after building
|
tags: ${{ steps.meta.outputs.tags }} # Use tags from metadata step
|
||||||
tags: ${{ steps.meta.outputs.tags }} # Use tags generated by the metadata step
|
labels: ${{ steps.meta.outputs.labels }} # Use labels from metadata step
|
||||||
labels: ${{ steps.meta.outputs.labels }} # Add labels generated by the metadata step
|
cache-from: type=gha
|
||||||
cache-from: type=gha # Enable build cache using GitHub Actions cache (works with Forgejo too)
|
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
4
.idea/vcs.xml
generated
4
.idea/vcs.xml
generated
|
@ -1,4 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings" defaultProject="true" />
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
Loading…
Add table
Add a link
Reference in a new issue