Skip to content

Commit

Permalink
publish automatically on main and manually on other branches
Browse files Browse the repository at this point in the history
  • Loading branch information
nisrael committed Jun 2, 2024
1 parent 02ecd11 commit 76f8f36
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: build and publish on demand

on:
push:
branches: [ "**" ]
workflow_dispatch:
push:
branches: [ "main" ]

env:
DOCKER_REGISTRY: ghcr.io
DOCKER_IMAGE_REGISTRY: ghcr.io/${{ github.repository }}
DOCKER_TAG_SHA: ${{ github.sha }}
DOCKER_TAG_REF: ${{ github.ref_name }}
DOCKER_TAG_REF: ${{ replace(github.ref_name, '/', '_') }}
DOCKER_REGISTRY_USERNAME: ${{ github.actor }}
DOCKER_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

Expand Down Expand Up @@ -40,8 +40,8 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push image except on PR
if: github.event_name != 'pull_request'
- name: Build and push image except for main branch
if: github.ref != 'refs/heads/main'
run: |
./mvnw install \
-B --no-transfer-progress --file pom.xml \
Expand All @@ -50,3 +50,13 @@ jobs:
-D docker.app.image.tag.ref=${{ env.DOCKER_TAG_REF }} \
-D docker.app.image.tag.sha=${{ env.DOCKER_TAG_SHA }} \
-am -pl addondemo.app.image
- name: Build and push image for main branch
if: github.ref == 'refs/heads/main'
run: |
./mvnw install \
-B --no-transfer-progress --file pom.xml \
-D docker.app.image.registry=${{ env.DOCKER_IMAGE_REGISTRY }} \
-P exec.docker.image \
-D docker.app.image.tag.sha=${{ env.DOCKER_TAG_SHA }} \
-am -pl addondemo.app.image
1 change: 0 additions & 1 deletion addondemo.app.image/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<to>
<image>${docker.app.image.registry}/app</image>
<tags>
<tag>${docker.app.image.tag.latest}</tag>
<tag>${docker.app.image.tag.ref}</tag>
<tag>${docker.app.image.tag.sha}</tag>
</tags>
Expand Down
4 changes: 1 addition & 3 deletions addondemo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
<master_plugin_jib_version>3.4.3</master_plugin_jib_version>
<!-- build target (push) -->
<docker.app.image.registry>localhost:5000</docker.app.image.registry> <!-- set a desired registry before using profile exec.docker.image (e.g. registry.hub.docker.com/yourusername) -->
<docker.app.image.name>24.1</docker.app.image.name>
<docker.app.image.tag.latest>24.1-latest</docker.app.image.tag.latest>
<docker.app.image.tag.ref>ref</docker.app.image.tag.ref>
<docker.app.image.tag.ref>24.1-latest</docker.app.image.tag.ref>
<docker.app.image.tag.sha>sha</docker.app.image.tag.sha>
<!-- java source image (pull) -->
<docker.java.image.registry>docker.io</docker.java.image.registry>
Expand Down

0 comments on commit 76f8f36

Please sign in to comment.