name: Publish container image on: push: branches: [main] workflow_dispatch: env: IMAGE_NAME: gt.uo1.net/1movmedia/ollama-with-model jobs: build: runs-on: ubuntu-latest outputs: digest: ${{ steps.build.outputs.digest }} steps: - uses: actions/checkout@v4 - name: Log in to Gitea registry uses: docker/login-action@v3 with: registry: gt.uo1.net username: ${{ vars.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_TOKEN }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 - name: Build image id: build uses: docker/build-push-action@v7 with: context: . outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true publish: runs-on: ubuntu-latest needs: build steps: - name: Log in to Gitea registry uses: docker/login-action@v3 with: registry: gt.uo1.net username: ${{ vars.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_TOKEN }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 - name: Publish latest tag run: docker buildx imagetools create --tag "${IMAGE_NAME}:latest" "${IMAGE_NAME}@${{ needs.build.outputs.digest }}" - name: Remove old image versions env: REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} run: | set -eu command -v jq >/dev/null api='https://gt.uo1.net/api/v1/packages/1movmedia/container/ollama-with-model' while :; do response=$(curl --fail --silent --show-error \ --header "Authorization: token ${REGISTRY_TOKEN}" \ "${api}?page=1&limit=100") versions=$(printf '%s\n' "$response" \ | jq --raw-output '.[] | select(.version != "latest") | .version') [ -n "$versions" ] || break printf '%s\n' "$versions" | while IFS= read -r version; do curl --fail --silent --show-error --request DELETE \ --header "Authorization: token ${REGISTRY_TOKEN}" \ "${api}/${version}" done done