Skip to content

Commit

Permalink
Adds github actions to build and push images based on branches and tags
Browse files Browse the repository at this point in the history
  • Loading branch information
danperezsan committed Jun 5, 2024
1 parent d54fc31 commit 238cca4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
with:
context: .
push: true
tags: mesoform/postgres-ha:${{ env.BRANCH_NAME }}
tags: mesoform/postgres-ha:${{ env.BRANCH_NAME }}
15 changes: 6 additions & 9 deletions .github/workflows/build_main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: Build and Push Dev Image
name: Build and Push Docker Image on Merged Pull Request

on:
push:
branches:
- 'main'
pull_request:
types: [closed]

jobs:
build:
if: ${{ github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' && startsWith(github.event.pull_request.head.ref, 'pg-v') }}

runs-on: ubuntu-latest

steps:
Expand All @@ -22,13 +23,9 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract branch name
id: extract_branch
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV

- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: mesoform/postgres-ha:latest
tags: mesoform/postgres-ha:latest
15 changes: 8 additions & 7 deletions .github/workflows/build_prod.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: Build and Push Dev Image
name: Build and Push Docker Image on Merged Pull Request

on:
push:
branches:
- 'pg-v*'
pull_request:
types: [closed]

jobs:
build:
if: ${{ github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'dev-') && startsWith(github.event.pull_request.base.ref, 'pg-v') }}

runs-on: ubuntu-latest

steps:
Expand All @@ -22,13 +23,13 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract branch name
- name: Extract target branch name
id: extract_branch
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
run: echo "TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV

- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: mesoform/postgres-ha:${{ env.BRANCH_NAME }}
tags: mesoform/postgres-ha:${{ env.TARGET_BRANCH }}
6 changes: 3 additions & 3 deletions .github/workflows/build_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ jobs:
context: .
push: true
tags: |
my-dockerhub-username/my-image:release-${{ env.VERSION }}
my-dockerhub-username/my-image:release-${{ env.MAJOR_MINOR }}
my-dockerhub-username/my-image:${{ env.MAJOR }}-latest
mesoform/postgres-ha:release-${{ env.VERSION }}
mesoform/postgres-ha:release-${{ env.MAJOR_MINOR }}
mesoform/postgres-ha:${{ env.MAJOR }}-latest

0 comments on commit 238cca4

Please sign in to comment.