From fe8db39f562fd7e6224c5d766fb6dddd22fb23fb Mon Sep 17 00:00:00 2001 From: Steven Ontong Date: Fri, 26 Jul 2024 08:52:28 +0200 Subject: [PATCH] fix Docker image release --- .github/workflows/image_release.yaml | 62 -------------------- .github/workflows/packages_release.yaml | 76 +++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 62 deletions(-) delete mode 100644 .github/workflows/image_release.yaml diff --git a/.github/workflows/image_release.yaml b/.github/workflows/image_release.yaml deleted file mode 100644 index 656e9f7..0000000 --- a/.github/workflows/image_release.yaml +++ /dev/null @@ -1,62 +0,0 @@ -# Publishes the Docker image to DockerHub -# This is triggered whenever the `service` is versioned and tagged -name: Docker Image Release - -on: - push: - tags: - - '@powersync/service-image*' - -concurrency: ${{ github.workflow }}-${{ github.ref }} - -jobs: - release-docker-image: - name: Build and Release powersync-service Docker Image - runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - # check out full history - # Temporarily needed for changesets - fetch-depth: 0 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - # This uses the service's package.json version for the Docker Image tag - - name: Get Service Version from package.json - id: get_version - run: echo "SERVICE_VERSION=$(node -p "require('./service/package.json').version")" >> $GITHUB_OUTPUT - - - name: Build Image and Push - uses: docker/build-push-action@v5 - with: - platforms: linux/arm64,linux/amd64 - cache-from: type=registry,ref=${{vars.DOCKER_REGISTRY}}:latest - context: . - tags: ${{vars.DOCKER_REGISTRY}}:latest,${{vars.DOCKER_REGISTRY}}:${{steps.get_version.outputs.SERVICE_VERSION}} - push: true - file: ./service/Dockerfile - - # # Updates the README section on the DockerHub page - - name: Update repo description - # Note that this 3rd party extention is recommended in the DockerHub docs: - # https://docs.docker.com/build/ci/github-actions/update-dockerhub-desc/ - uses: peter-evans/dockerhub-description@e98e4d1628a5f3be2be7c231e50981aee98723ae # v4.0.0 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - repository: ${{vars.DOCKER_REGISTRY}} - # This is the contents of what will be shown on DockerHub - readme-filepath: ./service/README.md diff --git a/.github/workflows/packages_release.yaml b/.github/workflows/packages_release.yaml index 224c745..e9e2f76 100644 --- a/.github/workflows/packages_release.yaml +++ b/.github/workflows/packages_release.yaml @@ -11,6 +11,8 @@ jobs: release-packages: name: Release Packages runs-on: ubuntu-latest + outputs: + dockerReleaseCreated: ${{ steps.check_docker_release.outputs.docker_image_release_created }} steps: - name: Checkout Repo uses: actions/checkout@v4 @@ -55,3 +57,77 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Check if @powersync/service-image Released + id: check_docker_release + if: steps.changesets.outputs.published == 'true' + run: | + packages="${{ toJson(steps.changesets.outputs.publishedPackages) }}" + echo "Packages: $packages" # Debugging output + + # Use jq to check if the specific package is in the array + # Ensure the JSON is valid by echoing it into jq + echo "$packages" | jq -e '[.[] | select(.name == "@powersync/service-image")] | length > 0' > /dev/null + if [ $? -eq 0 ]; then + echo "docker_image_release_created=true" >> $GITHUB_OUTPUT + else + echo "docker_image_release_created=false" >> $GITHUB_OUTPUT + fi + + - name: Debug Outputs + run: | + echo "Published Packages: ${{ steps.changesets.outputs.publishedPackages }}" + echo "Released Docker Image: ${{ steps.check_docker_release.outputs.docker_image_release_created }}" + + release-docker-image: + name: Build and Release powersync-service Docker Image + runs-on: ubuntu-latest + needs: release-packages + # Only run this job if the previous release job created a release for @powersync/service-image + if: needs.release-packages.outputs.dockerReleaseCreated == 'true' + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + # check out full history + # Temporarily needed for changesets + fetch-depth: 0 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # This uses the service's package.json version for the Docker Image tag + - name: Get Service Version from package.json + id: get_version + run: echo "SERVICE_VERSION=$(node -p "require('./service/package.json').version")" >> $GITHUB_OUTPUT + + - name: Build Image and Push + uses: docker/build-push-action@v5 + with: + platforms: linux/arm64,linux/amd64 + cache-from: type=registry,ref=${{vars.DOCKER_REGISTRY}}:latest + context: . + tags: ${{vars.DOCKER_REGISTRY}}:latest,${{vars.DOCKER_REGISTRY}}:${{steps.get_version.outputs.SERVICE_VERSION}} + push: true + file: ./service/Dockerfile + + # # Updates the README section on the DockerHub page + - name: Update repo description + # Note that this 3rd party extention is recommended in the DockerHub docs: + # https://docs.docker.com/build/ci/github-actions/update-dockerhub-desc/ + uses: peter-evans/dockerhub-description@e98e4d1628a5f3be2be7c231e50981aee98723ae # v4.0.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + repository: ${{vars.DOCKER_REGISTRY}} + # This is the contents of what will be shown on DockerHub + readme-filepath: ./service/README.md