51 lines
1.7 KiB
YAML
51 lines
1.7 KiB
YAML
name: Build Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
LOCAL_IMAGE_NAME: wdw-sitemap-and-importer
|
|
REGISTRY: ${{ secrets.REGISTRY_URL }}
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
jobs:
|
|
docker:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check out repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Build image
|
|
run: docker build -t "${LOCAL_IMAGE_NAME}:${{ gitea.sha }}" .
|
|
|
|
- name: Tag latest image
|
|
run: docker tag "${LOCAL_IMAGE_NAME}:${{ gitea.sha }}" "${LOCAL_IMAGE_NAME}:latest"
|
|
|
|
- name: Log in and push image
|
|
run: |
|
|
if [ -z "${REGISTRY}" ] || [ -z "${REGISTRY_USERNAME}" ] || [ -z "${REGISTRY_PASSWORD}" ]; then
|
|
echo "Registry secrets are not fully configured. Skipping registry login and push."
|
|
echo "Expected secrets: REGISTRY_URL, REGISTRY_USERNAME, REGISTRY_PASSWORD"
|
|
exit 0
|
|
fi
|
|
|
|
REGISTRY_HOST="${REGISTRY#http://}"
|
|
REGISTRY_HOST="${REGISTRY_HOST#https://}"
|
|
REGISTRY_HOST="${REGISTRY_HOST%/}"
|
|
IMAGE_REPOSITORY="$(printf '%s' '${{ gitea.repository }}' | tr '[:upper:]' '[:lower:]')"
|
|
FULL_IMAGE="${REGISTRY_HOST}/${IMAGE_REPOSITORY}"
|
|
|
|
echo "Pushing image to ${FULL_IMAGE}"
|
|
|
|
echo "${REGISTRY_PASSWORD}" | docker login "${REGISTRY_HOST}" -u "${REGISTRY_USERNAME}" --password-stdin
|
|
|
|
docker tag "${LOCAL_IMAGE_NAME}:${{ gitea.sha }}" "${FULL_IMAGE}:${{ gitea.sha }}"
|
|
docker tag "${LOCAL_IMAGE_NAME}:latest" "${FULL_IMAGE}:latest"
|
|
|
|
docker push "${FULL_IMAGE}:${{ gitea.sha }}"
|
|
docker push "${FULL_IMAGE}:latest"
|