Skip to content

Commit

Permalink
Feature/jib docker build (#6)
Browse files Browse the repository at this point in the history
* fix jib image build
* publish automatically on main and manually on other branches
* add auth for dockerhub public images (because of rate limits)
* specify base image add prefix: library
  • Loading branch information
nisrael authored Jun 2, 2024
1 parent 4ca72c3 commit e39fc51
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 44 deletions.
32 changes: 3 additions & 29 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
name: build, package and deploy java parts
name: build and verify

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

env:
DOCKER_REGISTRY: ghcr.io
DOCKER_IMAGE_NAME: ${{ github.repository }}
DOCKER_TAG_SHA: ${{ github.sha }}
DOCKER_TAG_REF: ${{ github.ref_name }}

jobs:
build-and-push-image:
build-and-verify:
runs-on: ubuntu-latest

permissions:
Expand All @@ -24,14 +18,6 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Log into registry ${{ env.DOCKER_REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/setup-java@v4
with:
java-version: '17'
Expand All @@ -48,15 +34,3 @@ jobs:
uses: scacap/action-surefire-report@v1
with:
report_paths: '**/surefire-reports/TEST-*.xml, **/failsafe-reports/TEST-*.xml, **/karma-reports/**/test-*.xml'

- name: Build and push image except on PR
if: github.event_name != 'pull_request'
run: |
./mvnw install \
-B --no-transfer-progress --file pom.xml \
-P exec.docker.image \
-D docker.app.image.registry=${{ env.DOCKER_REGISTRY }} \
-D docker.app.image.name=${{ env.DOCKER_IMAGE_NAME }} \
-D docker.app.image.tag=${{ env.DOCKER_TAG_REF }} \
-D docker.app.image.tag2=${{ env.DOCKER_TAG_SHA }} \
-am -pl addondemo.app.image
59 changes: 59 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: build and publish image

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

env:
DOCKER_IMAGE_REGISTRY: ghcr.io/${{ github.repository }}
DOCKER_REGISTRY_USERNAME: ${{ github.actor }}
DOCKER_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}


jobs:
build-and-publish-image:
runs-on: ubuntu-latest

permissions:
checks: write
contents: read
packages: write

steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: Set DOCKER_APP_IMAGE for all branches except main
if: github.ref != 'refs/heads/main'
run: echo "DOCKER_APP_IMAGE=$(echo ${{ env.DOCKER_IMAGE_REGISTRY }}:${GITHUB_SHA::7})" >> $GITHUB_ENV

- name: Set DOCKER_APP_IMAGE for main branch
if: github.ref == 'refs/heads/main'
run: echo "DOCKER_APP_IMAGE=$(echo ${{ env.DOCKER_IMAGE_REGISTRY }}:latest})" >> $GITHUB_ENV

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push image
run: |
./mvnw install \
-B --no-transfer-progress --file pom.xml \
-D docker.app.image=${{ env.DOCKER_APP_IMAGE }} \
-P exec.docker.image \
-am -pl addondemo.app.image
6 changes: 1 addition & 5 deletions addondemo.app.image/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<to>
<image>${docker.app.image.registry}/addondemo</image>
<tags>
<tag>${docker.app.image.tag}</tag>
<tag>${docker.app.image.tag2}</tag>
</tags>
<image>${docker.app.image}</image>
</to>
<from>
<image>${docker.java.image}</image>
Expand Down
9 changes: 3 additions & 6 deletions addondemo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
<master_npm_release_dependency_mapping>--mapping.0.regex=@eclipse-scout --mapping.0.version=${org.eclipse.scout.rt.version}</master_npm_release_dependency_mapping>

<!-- docker image build settings -->
<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.tag>24.1</docker.app.image.tag>
<docker.app.image.tag2>24.1-latest</docker.app.image.tag2>
<docker.app.image>localhost:5000/app</docker.app.image> <!-- set a desired registry before using profile exec.docker.image (e.g. registry.hub.docker.com/yourusername) -->
<!-- java source image (pull) -->
<docker.java.image.name>eclipse-temurin</docker.java.image.name>
<docker.java.image.tag>17-jdk-jammy</docker.java.image.tag>
<docker.java.image>${docker.java.image.name}:${docker.java.image.tag}</docker.java.image>
<docker.java.image>registry-1.docker.io/library/eclipse-temurin:17-jdk-jammy</docker.java.image>
<sxda.addon.version>24.1.3</sxda.addon.version>
</properties>

Expand Down
6 changes: 2 additions & 4 deletions addondemo/run-configs/js build.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2">
<option name="RunConfigurationTask" enabled="true" run_configuration_name="pnpm-install" run_configuration_type="js.build_tools.npm" />
</method>
<method v="2" />
</configuration>
</component>
</component>

0 comments on commit e39fc51

Please sign in to comment.