Add .gitea/workflows/docker-publish.yml
This commit is contained in:
75
.gitea/workflows/docker-publish.yml
Normal file
75
.gitea/workflows/docker-publish.yml
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
name: Build & Push to Gitea Registry (version.txt trigger)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main, master ]
|
||||||
|
paths:
|
||||||
|
- version.txt
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ${{ vars.REGISTRY }}
|
||||||
|
IMAGE: ${{ github.repository }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Read version.txt
|
||||||
|
id: ver
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
VERSION="$(cat version.txt | tr -d '\r\n' | xargs)"
|
||||||
|
if [ -z "$VERSION" ]; then
|
||||||
|
echo "version.txt is empty" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Ensure Dockerfile exists
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
if [ -f Dockerfile ]; then
|
||||||
|
echo "Dockerfile already exists."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Dockerfile missing; generating one..."
|
||||||
|
cat > Dockerfile <<'EOF'
|
||||||
|
FROM nginx:alpine
|
||||||
|
COPY website/ /usr/share/nginx/html/
|
||||||
|
COPY default.conf /etc/nginx/conf.d/default.conf
|
||||||
|
EXPOSE 80
|
||||||
|
EOF
|
||||||
|
|
||||||
|
ls -la Dockerfile
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to Gitea Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ secrets.USER }}
|
||||||
|
password: ${{ secrets.TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
push: true
|
||||||
|
build-args: |
|
||||||
|
VERSION=${{ steps.ver.outputs.version }}
|
||||||
|
tags: |
|
||||||
|
${{ env.REGISTRY }}/${{ env.IMAGE }}:latest
|
||||||
|
${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ steps.ver.outputs.version }}
|
||||||
|
${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ github.sha }}
|
||||||
Reference in New Issue
Block a user