Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): backend arm builds, create dockerfile #1831

Merged
merged 16 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ name: backend
on:
push:
workflow_dispatch:
inputs:
build_arm:
type: boolean
description: "Build for ARM as well"
default: false
required: false

env:
DOCKER_IMAGE_NAME: ghcr.io/loculus-project/backend
BUILD_ARM: ${{ github.ref == 'refs/heads/main' || github.event.inputs.build_arm }}

concurrency:
group: ci-${{ github.ref == 'refs/heads/main' && github.run_id || github.ref }}-backend
Expand All @@ -26,7 +36,7 @@ jobs:
id: files-hash
run: |
DIR_HASH=$(echo -n ${{ hashFiles('backend/**', '.github/workflows/backend.yml') }})
echo "DIR_HASH=$DIR_HASH" >> $GITHUB_ENV
echo "DIR_HASH=$DIR_HASH${{ env.BUILD_ARM && '-arm'|| '' }}" >> $GITHUB_ENV

- name: Setup Docker metadata
id: dockerMetadata
Expand All @@ -52,6 +62,9 @@ jobs:
EXISTS=$(docker manifest inspect ${{ env.DOCKER_IMAGE_NAME }}:${{ env.DIR_HASH }} > /dev/null 2>&1 && echo "true" || echo "false")
echo "CACHE_HIT=$EXISTS" >> $GITHUB_ENV

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set up JDK
if: env.CACHE_HIT == 'false'
uses: actions/setup-java@v4
Expand All @@ -63,22 +76,24 @@ jobs:
if: env.CACHE_HIT == 'false'
uses: gradle/actions/setup-gradle@v3

- name: Build Docker Image For Branch
- name: Build Backend
if: env.CACHE_HIT == 'false'
run: ./gradlew bootBuildImage --imageName=${{ env.DOCKER_IMAGE_NAME }}:${{ env.DIR_HASH }}
working-directory: ./backend
env:
USER: ${{ github.actor }}
TOKEN: "${{ secrets.GITHUB_TOKEN }}"
run: ./gradlew bootJar

- name: Push Docker Image
- name: Build and push image if input files changed
if: env.CACHE_HIT == 'false'
run: docker push ${{ env.DOCKER_IMAGE_NAME }}:${{ env.DIR_HASH }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
uses: docker/build-push-action@v5
with:
context: ./backend
push: true
tags: ${{ steps.dockerMetadata.outputs.tags }}
cache-from: type=gha,scope=backend-${{ github.ref }}
cache-to: type=gha,mode=max,scope=backend-${{ github.ref }}
platforms: ${{ env.BUILD_ARM && 'linux/amd64,linux/arm64' || 'linux/amd64' }}

- name: Tag and push existing images
- name: Retag and push existing image if cache hit
if: env.CACHE_HIT == 'true'
run: |
TAGS=(${{ steps.dockerMetadata.outputs.tags }})
for TAG in "${TAGS[@]}"; do
Expand Down
9 changes: 9 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM eclipse-temurin:21-jre-alpine

WORKDIR /app

COPY build/libs/backend.jar app.jar

EXPOSE 8079

ENTRYPOINT ["java", "-jar", "app.jar", "--spring.profiles.active=docker"]
8 changes: 8 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ tasks.named('bootBuildImage') {
// https://paketo.io/docs/howto/configuration/
environment["BPE_SPRING_PROFILES_ACTIVE"] = "docker"
}

tasks.named("jar") {
enabled = false // prevent to generate plain jar
}
tasks.named("bootJar") {
enabled = true
archiveVersion.set("")
}
Loading