diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index e695d72..917b9bb 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -13,34 +13,54 @@ jobs: build-and-push: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + - name: Docker Setup QEMU + uses: docker/setup-qemu-action@v1 - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Docker Setup Buildx + uses: docker/setup-buildx-action@v1 - - name: Set tag name - id: tag_name - run: | - if [ "${{ github.event_name }}" = "release" ]; then - echo "::set-output name=tag::${GITHUB_REF#refs/tags/}" - elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then - echo "::set-output name=tag::${{ github.event.inputs.tag }}" - fi + - name: Docker Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Build and push Docker image with Release tag - uses: docker/build-push-action@v2 - with: - context: . - file: ./Dockerfile - push: true - tags: | - vinlic/step-free-api:${{ steps.tag_name.outputs.tag }} - vinlic/step-free-api:latest - platforms: linux/amd64,linux/arm64 - build-args: TARGETPLATFORM=${{ matrix.platform }} + - name: Docker Login to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set tag name + id: tag_name + run: | + if [ "${{ github.event_name }}" = "release" ]; then + echo "::set-output name=tag::${GITHUB_REF#refs/tags/}" + elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "::set-output name=tag::${{ github.event.inputs.tag }}" + fi + + - name: Set Docker repository names + id: repo-set + run: | + echo "::set-output name=repo_all::$(echo "${{ github.repository }}" | awk '{print tolower($0)}')" + echo "::set-output name=repo_name::$(echo "${{ github.event.repository.name }}" | awk '{print tolower($0)}')" + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + push: true + tags: | + vinlic/${{ steps.repo-set.outputs.repo_name }}:${{ steps.tag_name.outputs.tag }} + vinlic/${{ steps.repo-set.outputs.repo_name }}:latest + ghcr.io/${{ steps.repo-set.outputs.repo_all }}:${{ steps.tag_name.outputs.tag }} + ghcr.io/${{ steps.repo-set.outputs.repo_all }}:latest + platforms: linux/amd64,linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max