51 lines
1.6 KiB
YAML
51 lines
1.6 KiB
YAML
name: Build and push image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
REGISTRY: gitea.alexandre-vazquez.cloud
|
|
IMAGE_NAME: alexandrev/hidden11
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
run: |
|
|
AUTH="$(printf '%s:%s' '${{ secrets.REGISTRY_USERNAME }}' '${{ secrets.REGISTRY_TOKEN }}' | base64 -w0)"
|
|
echo "::add-mask::${AUTH}"
|
|
git init .
|
|
git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
|
|
git -c "http.extraHeader=Authorization: Basic ${AUTH}" \
|
|
fetch --depth=1 origin "${GITHUB_SHA}"
|
|
git checkout --detach FETCH_HEAD
|
|
|
|
- name: Set image tags
|
|
id: meta
|
|
run: |
|
|
SHORT_SHA="${GITHUB_SHA::12}"
|
|
echo "sha_tag=${REGISTRY}/${IMAGE_NAME}:${SHORT_SHA}" >> "$GITHUB_OUTPUT"
|
|
echo "latest_tag=${REGISTRY}/${IMAGE_NAME}:latest" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Login to Gitea registry
|
|
run: |
|
|
printf '%s' "${{ secrets.REGISTRY_TOKEN }}" \
|
|
| docker login "${REGISTRY}" \
|
|
--username "${{ secrets.REGISTRY_USERNAME }}" \
|
|
--password-stdin
|
|
|
|
- name: Build and push
|
|
run: |
|
|
docker build \
|
|
--label "org.opencontainers.image.source=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" \
|
|
--label "org.opencontainers.image.revision=${GITHUB_SHA}" \
|
|
--tag "${{ steps.meta.outputs.sha_tag }}" \
|
|
--tag "${{ steps.meta.outputs.latest_tag }}" \
|
|
.
|
|
docker push "${{ steps.meta.outputs.sha_tag }}"
|
|
docker push "${{ steps.meta.outputs.latest_tag }}"
|