From 765276022e81e9af82a87baa5c904c657f2d59a2 Mon Sep 17 00:00:00 2001 From: Versilis Tyson <100976287+versilis@users.noreply.github.com> Date: Thu, 20 Apr 2023 20:21:19 -0500 Subject: [PATCH] Push image automatically when a new release is published (#56) This will automatically push a new image to DockerHub anytime a Github release is published. It should replicate our manual deployment flow that is described here (excluding the verification step): https://www.notion.so/akitasoftware/Deploying-Docker-Extension-842700866ba74f20a357dbdcc3be642f --- .github/workflows/publish.yml | 71 +++++++++++++++++++++++++++++++++++ application.yml | 5 +++ 2 files changed, 76 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..0f0661f --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,71 @@ +name: Publish Docker Extension + +on: + release: + types: + - published + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout Release Tag + uses: actions/checkout@v3 + with: + ref: ${{ github.event.release.tag_name }} + + - name: Validate Release Tag + run: | + # Extract tag name without 'v' prefix + TAG_NAME=${{ github.event.release.tag_name }} + VERSION=${TAG_NAME#v} + + echo "app_version=$VERSION" >> $GITHUB_ENV + + # Check if the version (extracted from the tag name) is a valid semantic version without pre-release or metadata + # If so, we will publish this as the latest release on DockerHub + LATEST='false' + if echo "$VERSION" | grep -Eq '^([0-9]+\.[0-9]+\.[0-9]+)$'; then + LATEST='true' + fi + + echo "latest=$LATEST" >> $GITHUB_ENV + + - name: Update app configuration + env: + SEGMENT_WRITE_KEY: ${{ secrets.segment_write_key }} + VERSION: ${{ env.app_version }} + run: | + # Set analytics enabled to true + sed -i 's/enabled: false/enabled: true/' application.yml + + # Replace '' with secret + sed -i "s//${SEGMENT_WRITE_KEY}/" application.yml + + # Replace '' with the extracted version value + sed -i "s//${VERSION}/" application.yml + + - name: Setup QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + + - name: Publish to Dockerhub + env: + TAG: ${{ env.app_version }} + LATEST: ${{ env.latest }} + run: | + if [ "$LATEST" = 'true' ]; then + make push-extension-latest + else + make push-extension + fi diff --git a/application.yml b/application.yml index bd5fe66..e4dc9d9 100644 --- a/application.yml +++ b/application.yml @@ -1,2 +1,7 @@ analytics: enabled: false + segment_write_key: + app: + name: docker-extension + version: + batch_size: 1