Skip to content

Commit

Permalink
Merge pull request #6733 from reactioncommerce/feat/improve-docker-re…
Browse files Browse the repository at this point in the history
…lease-flow

feat: improve docker release flow
  • Loading branch information
brent-hoover authored Mar 14, 2023
2 parents a5e648e + c94313e commit 08bbe34
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
11 changes: 8 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ jobs:
- run:
name: Check should build new image
command: |
VERSION=$(cat ./apps/reaction/package.json | grep -m 1 version | sed 's/[^0-9.]//g')
if curl --silent -f --head -lL https://hub.docker.com/v2/repositories/${DOCKER_REPOSITORY}/tags/${VERSION}/ > /dev/null; then
head_commit=$(git log -1 --oneline | grep -m 1 releases)
if [[ $head_commit != *"/releases/docker-image"* ]]; then
circleci-agent step halt
fi
- run:
Expand Down Expand Up @@ -260,4 +260,9 @@ workflows:
only:
- trunk
requires:
- release
- dockerfile-lint
- eslint
- graphql-lint
- test-unit
- test-integration-query
- test-integration-mutation
60 changes: 60 additions & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Docker release
on:
pull_request:
types:
- closed

permissions: {}

jobs:
create-docker-release-pr:
if: github.event.pull_request.merged == true && github.base_ref == 'trunk' && github.head_ref == 'changeset-release/trunk'
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Get new docker version
id: get-docker-version
run: |
VERSION=$(cat ./apps/reaction/package.json | grep -m 1 version | sed 's/[^0-9.]//g')
echo "NEW_DOCKER_IMAGE_VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "New release docker version is $VERSION"
- name: Check should build new image
id: should-build-new-image
run: |
if curl --silent -f --head -lL https://hub.docker.com/v2/repositories/reactioncommerce/reaction/tags/${{ steps.get-docker-version.outputs.NEW_DOCKER_IMAGE_VERSION }}/ > /dev/null; then
echo "RESULT=false" >> $GITHUB_OUTPUT
else
echo "RESULT=true" >> $GITHUB_OUTPUT
fi
- name: Set git user
if: steps.should-build-new-image.outputs.RESULT == 'true'
run: |
echo ${{ steps.should-build-new-image.outputs.RESULT }}
git config --global user.name "$(git --no-pager log --format=format:'%an' -n 1)"
git config --global user.email "$(git --no-pager log --format=format:'%ae' -n 1)"
- name: Update docker-compose file
if: steps.should-build-new-image.outputs.RESULT == 'true'
run: |
yes | cp -i docker-compose.circleci.yml docker-compose.yml
sed -i "s/REACTION_VERSION/${{ steps.get-docker-version.outputs.NEW_DOCKER_IMAGE_VERSION }}/g" ./docker-compose.yml
- name: Create Pull Request
if: steps.should-build-new-image.outputs.RESULT == 'true'
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: Docker image release ${{ steps.get-docker-version.outputs.NEW_DOCKER_IMAGE_VERSION }}
body: "Release docker image ${{ steps.get-docker-version.outputs.NEW_DOCKER_IMAGE_VERSION }}"
branch: "releases/docker-image-${{ steps.get-docker-version.outputs.NEW_DOCKER_IMAGE_VERSION }}"
commit-message: "feat: update docker-compose file to ${{ steps.get-docker-version.outputs.NEW_DOCKER_IMAGE_VERSION }} [Docker Release]"
signoff: true

0 comments on commit 08bbe34

Please sign in to comment.