54 lines
2.0 KiB
YAML
54 lines
2.0 KiB
YAML
name: Build Docker Image
|
|
run-name: ${{ gitea.actor }} building ${{ gitea.ref_name }}
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- dev
|
|
|
|
jobs:
|
|
Docker-Build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Clone Repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Build docker image
|
|
run: |
|
|
docker build -t umbrella .
|
|
docker tag umbrella ${{ secrets.REGISTRY_PATH }}/umbrella:${{ gitea.ref_name }}
|
|
|
|
- name: Login to registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ${{ secrets.REGISTRY_PATH }}
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_PASS }}
|
|
|
|
- name: Re-tag the most recent image
|
|
run: |
|
|
set -x
|
|
REGISTRY="${{ secrets.REGISTRY_PATH }}"
|
|
REPO="umbrella"
|
|
USER="${{ secrets.DOCKER_USERNAME }}"
|
|
PASS="${{ secrets.DOCKER_PASSWORD }}"
|
|
LATEST="${{ gitea.ref_name }}"
|
|
NEW_TAG="${{ gitea.sha_short }}"
|
|
|
|
# Get auth token (basic auth for most self-hosted registries)
|
|
#TOKEN=$(curl -s -u "$USER:$PASS" "https://$REGISTRY/v2/token?service=$REGISTRY&scope=repository:$REPO:pull,push")
|
|
#AUTH="Bearer $(echo $TOKEN | jq -r .token)"
|
|
|
|
# Fetch latest manifest (specify mediaType header for OCI support)
|
|
MANIFEST=$(curl -s -u "$USER:$PASS" -H "Accept: application/vnd.docker.distribution.manifest.v2+json,application/vnd.oci.image.manifest.v1+json" "https://$REGISTRY/v2/$REPO/manifests/$LATEST" | jq -c .)
|
|
|
|
# PUT manifest under new tag
|
|
curl -X PUT -s -u "$USER:$PASS" -H "Content-Type: application/vnd.docker.distribution.manifest.v2+json" --data "$MANIFEST" "https://$REGISTRY/v2/$REPO/manifests/$NEW_TAG"
|
|
|
|
echo "Tagged $REGISTRY/$REPO:$LATEST -> $NEW_TAG"
|
|
|
|
- name: Push to registry
|
|
# if: startsWith(gitea.ref, 'refs/tags/')
|
|
run: |
|
|
docker push ${{ secrets.REGISTRY_PATH }}/umbrella:${{ gitea.ref_name }}
|