Skip to content

Build and Push Docker image to GitLab Registry #2

Build and Push Docker image to GitLab Registry

Build and Push Docker image to GitLab Registry #2

name: Build and Push Docker image to GitLab Registry
on:
workflow_dispatch:
permissions:
contents: read
packages: read
env:
REGISTRY: ${{ vars.GITLAB_REGISTRY || 'registry.gitlab.inria.fr' }}
PROJECT_PATH: ${{ vars.GITLAB_PROJECT_PATH || 'inocs-lab/inocs-sum-odp-frontend' }}
jobs:
docker:
name: Build and Push
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitLab Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: gitlab-ci-token
password: ${{ secrets.GITLAB_REGISTRY_TOKEN }}
- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.PROJECT_PATH }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha,format=short
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Show pushed tags
run: |
echo "Pushed:"
echo "${{ steps.meta.outputs.tags }}" | tr ' ' '\n'