Add .gitea/workflows/image-publish.yml
This commit is contained in:
76
.gitea/workflows/image-publish.yml
Normal file
76
.gitea/workflows/image-publish.yml
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
name: Build and Push Docker Images
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
```
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Generate tags
|
||||||
|
run: |
|
||||||
|
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
|
||||||
|
echo "BUILD_DATE=$(date -u +'%Y%m%d-%H%M%S')" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Login to Gitea Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: git.harryesses.com
|
||||||
|
username: ${{ gitea.repository_owner }}
|
||||||
|
password: ${{ secrets.PACKAGE_TOKEN }}
|
||||||
|
|
||||||
|
- name: Set repository name
|
||||||
|
run: |
|
||||||
|
REPO_NAME=$(basename "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
|
||||||
|
OWNER_NAME=$(dirname "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
|
echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV
|
||||||
|
echo "OWNER_NAME=$OWNER_NAME" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Build and Push Images
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
|
||||||
|
found=0
|
||||||
|
|
||||||
|
for dockerfile in *.dockerfile; do
|
||||||
|
[ -f "$dockerfile" ] || continue
|
||||||
|
|
||||||
|
found=1
|
||||||
|
|
||||||
|
IMAGE_VARIANT="${dockerfile%.dockerfile}"
|
||||||
|
IMAGE_NAME="git.harryesses.com/${OWNER_NAME}/${REPO_NAME}-${IMAGE_VARIANT}"
|
||||||
|
|
||||||
|
echo "======================================"
|
||||||
|
echo "Building $IMAGE_NAME"
|
||||||
|
echo "Dockerfile: $dockerfile"
|
||||||
|
echo "======================================"
|
||||||
|
|
||||||
|
docker build \
|
||||||
|
-f "$dockerfile" \
|
||||||
|
-t "${IMAGE_NAME}:latest" \
|
||||||
|
-t "${IMAGE_NAME}:${SHORT_SHA}" \
|
||||||
|
-t "${IMAGE_NAME}:${BUILD_DATE}" \
|
||||||
|
.
|
||||||
|
|
||||||
|
docker push "${IMAGE_NAME}:latest"
|
||||||
|
docker push "${IMAGE_NAME}:${SHORT_SHA}"
|
||||||
|
docker push "${IMAGE_NAME}:${BUILD_DATE}"
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$found" -eq 0 ]; then
|
||||||
|
echo "No *.dockerfile files found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user