Skip to content

Commit bedb8e8

Browse files
authored
AIR-10 Build docker image with BuildPacks (#23)
1 parent 8e0dfd1 commit bedb8e8

3 files changed

Lines changed: 24 additions & 60 deletions

File tree

.github/workflows/post-commit-pipeline.yml

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ jobs:
1313
runs-on: ubuntu-22.04
1414
outputs:
1515
new-version: ${{ steps.calculate_version.outputs.NEW_VERSION }}
16+
bump: ${{ steps.version_increment.outputs.bump }}
1617
steps:
1718
- name: Check out the repository
18-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
1920
with:
2021
fetch-depth: 0
2122

2223
- name: Set up JDK 21
23-
uses: actions/setup-java@v3
24+
uses: actions/setup-java@v4
2425
with:
2526
distribution: temurin
2627
java-version: 21
@@ -76,15 +77,21 @@ jobs:
7677
fi
7778
NEW_VERSION="$major.$minor.$patch"
7879
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
79-
- name: Set up environment variables
80-
run: echo "JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}" >> $GITHUB_ENV
8180
8281
- name: Build & Test
8382
run: ./gradlew clean build
8483

8584
- name: Run Linter Check
8685
run: ./gradlew spotlessCheck
8786

87+
- name: Build & push docker image
88+
if: steps.version_increment.outputs.bump != 'none'
89+
env:
90+
DOCKER_IMAGE_VERSION: "${{ steps.calculate_version.outputs.NEW_VERSION }}"
91+
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
92+
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}
93+
run: ./gradlew bootBuildImage
94+
8895
- name: Create GitHub Release
8996
if: steps.version_increment.outputs.bump != 'none'
9097
id: create_release
@@ -97,56 +104,10 @@ jobs:
97104
draft: false
98105
prerelease: false
99106

100-
- name: Find built JAR
101-
if: steps.version_increment.outputs.bump != 'none'
102-
id: find_jar
103-
run: |
104-
FILE=$(find build/libs -name "*.jar" | head -n 1)
105-
if [ -z "$FILE" ]; then
106-
exit 1
107-
fi
108-
echo "jar_file=$FILE" >> $GITHUB_OUTPUT
109-
110-
- name: Upload JAR to Release
111-
if: steps.version_increment.outputs.bump != 'none'
112-
uses: actions/upload-release-asset@v1
113-
env:
114-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115-
with:
116-
upload_url: ${{ steps.create_release.outputs.upload_url }}
117-
asset_path: ${{ steps.find_jar.outputs.jar_file }}
118-
asset_name: autoinvestor-${{ github.event.repository.name }}-${{ steps.calculate_version.outputs.NEW_VERSION }}.jar
119-
asset_content_type: application/java-archive
120-
121-
- name: Create app.jar
122-
if: steps.version_increment.outputs.bump != 'none'
123-
run: mv "${{ steps.find_jar.outputs.jar_file }}" app.jar
124-
125-
- name: Log in to Docker Hub
126-
if: steps.version_increment.outputs.bump != 'none'
127-
uses: docker/login-action@v2
128-
with:
129-
username: ${{ secrets.DOCKERHUB_USERNAME }}
130-
password: ${{ secrets.DOCKERHUB_TOKEN }}
131-
132-
- name: Build Docker Image
133-
if: steps.version_increment.outputs.bump != 'none'
134-
run: |
135-
docker build \
136-
--build-arg NEW_VERSION=${{ steps.calculate_version.outputs.NEW_VERSION }} \
137-
-t ${{ vars.DOCKERHUB_NAMESPACE }}/autoinvestor-${{ github.event.repository.name }}:${{ steps.calculate_version.outputs.NEW_VERSION }} \
138-
-t ${{ vars.DOCKERHUB_NAMESPACE }}/autoinvestor-${{ github.event.repository.name }}:latest \
139-
.
140-
141-
- name: Push Docker Image
142-
if: steps.version_increment.outputs.bump != 'none'
143-
run: |
144-
docker push ${{ vars.DOCKERHUB_NAMESPACE }}/autoinvestor-${{ github.event.repository.name }}:${{ steps.calculate_version.outputs.NEW_VERSION }}
145-
docker push ${{ vars.DOCKERHUB_NAMESPACE }}/autoinvestor-${{ github.event.repository.name }}:latest
146-
147107
update-cd-repo:
148108
uses: AutoInvestor/infra-gitops/.github/workflows/update-version.yml@main
149109
needs: build_test_release
110+
if: needs.build_test_release.outputs.bump != 'none'
150111
with:
151112
image: autoinvestor-users
152113
version: ${{ needs.build_test_release.outputs.new-version }}

Dockerfile

Lines changed: 0 additions & 9 deletions
This file was deleted.

build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,15 @@ spotless {
3737
eclipse().configFile 'config/eclipse-java-formatter.xml'
3838
}
3939
}
40+
41+
bootBuildImage {
42+
imageName = "${System.getenv("DOCKER_USERNAME")}/autoinvestor-${rootProject.name}:${System.getenv("DOCKER_IMAGE_VERSION")}"
43+
docker {
44+
publishRegistry {
45+
username = System.getenv("DOCKER_USERNAME")
46+
password = System.getenv("DOCKER_PASSWORD")
47+
url = "https://index.docker.io/v1/"
48+
}
49+
}
50+
publish = true
51+
}

0 commit comments

Comments
 (0)