diff --git a/.forgejo/workflows/docker-build.yml b/.forgejo/workflows/docker-build.yml index ed610f4..85d5284 100644 --- a/.forgejo/workflows/docker-build.yml +++ b/.forgejo/workflows/docker-build.yml @@ -18,41 +18,48 @@ env: jobs: build: - runs-on: ubuntu-latest + runs-on: docker steps: - name: Checkout uses: actions/checkout@v4 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + - name: Docker info + run: docker info - - name: Log into Forgejo Registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ secrets.FORGEJO_USERNAME }} - password: ${{ secrets.FORGEJO_PASSWORD }} + - name: Log into registry + run: echo "${{ secrets.FORGEJO_PASSWORD }}" | docker login ${{ env.REGISTRY }} -u ${{ secrets.FORGEJO_USERNAME }} --password-stdin - - name: Extract metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.IMAGE }} - tags: | - type=sha,prefix= - type=ref,event=branch - type=semver,pattern={{version}} - type=raw,value=latest,enable=${{ github.ref == 'refs/tags/v*' }} + - name: Determine tags + id: tags + run: | + SHA_SHORT=$(echo ${GITHUB_SHA} | cut -c1-7) + TAGS="${{ env.IMAGE }}:${SHA_SHORT}" + if [ "${GITHUB_REF}" = "refs/heads/main" ] || [ "${GITHUB_REF}" = "refs/heads/master" ]; then + TAGS="${TAGS},${{ env.IMAGE }}:main" + fi + if echo "${GITHUB_REF}" | grep -q "refs/tags/v"; then + VERSION=${GITHUB_REF#refs/tags/v} + TAGS="${TAGS},${{ env.IMAGE }}:${VERSION},${{ env.IMAGE }}:latest" + fi + echo "tags=${TAGS}" >> $GITHUB_OUTPUT + echo "Building tags: ${TAGS}" - name: Build and push - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - platforms: linux/amd64 - cache-from: type=gha - cache-to: type=gha,mode=max - build-args: | - NEXT_PUBLIC_API_URL=${{ github.event.inputs.api_url || 'http://ut.khoavo.myds.me:8981/api' }} + run: | + TAG_ARGS="" + IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.tags }}" + for tag in "${TAG_ARRAY[@]}"; do + TAG_ARGS="${TAG_ARGS} -t ${tag}" + done + echo "docker build ${TAG_ARGS} --build-arg NEXT_PUBLIC_API_URL=... ." + docker build \ + ${TAG_ARGS} \ + --build-arg NEXT_PUBLIC_API_URL=${{ github.event.inputs.api_url || 'http://ut.khoavo.myds.me:8981/api' }} \ + . + for tag in "${TAG_ARRAY[@]}"; do + echo "Pushing ${tag}..." + docker push "${tag}" + done + + - name: Verify + run: docker images | grep kv-tube