55 lines
1.4 KiB
YAML
55 lines
1.4 KiB
YAML
name: Build and Push Container Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- "v*"
|
|
|
|
env:
|
|
REGISTRY: ${{ gitea.server_url }}
|
|
IMAGE_NAME: ${{ gitea.repository }}
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: orchestration-platform
|
|
container:
|
|
image: gcr.io/kaniko-project/executor:debug
|
|
options: --entrypoint=""
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Determine image tag
|
|
id: meta
|
|
run: |
|
|
if echo "${{ gitea.ref }}" | grep -q "refs/tags/"; then
|
|
TAG=$(echo "${{ gitea.ref }}" | sed 's|refs/tags/||')
|
|
else
|
|
TAG="latest"
|
|
fi
|
|
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build and push image
|
|
run: |
|
|
REGISTRY_HOST=$(echo "${REGISTRY}" | sed 's|https\?://||')
|
|
AUTH=$(echo -n "${{ gitea.actor }}:${{ secrets.REGISTRY_TOKEN }}" | base64)
|
|
|
|
mkdir -p /kaniko/.docker
|
|
cat > /kaniko/.docker/config.json <<EOF
|
|
{
|
|
"auths": {
|
|
"${REGISTRY_HOST}": {
|
|
"auth": "${AUTH}"
|
|
}
|
|
}
|
|
}
|
|
EOF
|
|
|
|
/kaniko/executor \
|
|
--context "${GITHUB_WORKSPACE}" \
|
|
--dockerfile "${GITHUB_WORKSPACE}/Dockerfile" \
|
|
--destination "${REGISTRY_HOST}/${IMAGE_NAME}:${{ steps.meta.outputs.tag }}" \
|
|
--cache=true |