diff --git a/.github/workflows/main-cd.yml b/.github/workflows/main-cd.yml index f9833a1..8512e6c 100644 --- a/.github/workflows/main-cd.yml +++ b/.github/workflows/main-cd.yml @@ -3,35 +3,64 @@ name: Push image on Azure repository on: push: branches: ["main"] - pull_request: - branches: ["main"] workflow_dispatch: env: + IMAGE_NAME: codendui + IMAGE_REGISTRY: maksimowiczm DOCKERFILE: ./Dockerfile - IMAGE_NAME: ${{ secrets.AZURE_REGISTRY_LOGIN_SERVER }}/codend/frontend:latest jobs: - push-release-image: + push-release-image-azure: name: Push image on Azure registry runs-on: ubuntu-latest steps: - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Login to Azure registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ${{ secrets.AZURE_REGISTRY_LOGIN_SERVER }} username: ${{ secrets.AZURE_REGISTRY_USERNAME }} password: ${{ secrets.AZURE_REGISTRY_TOKEN }} - name: Docker build - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v5 with: + push: true + context: . + file: ${{ env.DOCKERFILE }} target: production - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ env.IMAGE_NAME }} + tags: | + ${{ secrets.AZURE_REGISTRY_LOGIN_SERVER }}/${{ secrets.AZURE_REGISTRY_NAME }}/${{ env.IMAGE_NAME }} + + push-release-image-dockerhub: + name: Push image on Docker Hub registry + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=sha + type=raw,value=latest,enable={{is_default_branch}} + + - name: Login to Docker Hub registry + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_HUB_REGISTRY_USERNAME }} + password: ${{ secrets.DOCKER_HUB_REGISTRY_TOKEN }} + + - name: Docker build + uses: docker/build-push-action@v5 + with: + push: true + context: . file: ${{ env.DOCKERFILE }} - cache-from: type=gha - cache-to: type=gha,mode=max + target: production + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}