Skip to content

Commit

Permalink
add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixTJDietrich committed Nov 27, 2024
1 parent 2e8e6ca commit 2a7f34d
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/build-and-push-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Build and Push Docker Image

on:
workflow_call:
inputs:
image-name:
type: string
default: ${{ github.repository }}
description: "The name for the docker image (Default: Repository name)"
docker-file:
type: string
default: Dockerfile
description: "The path to the Dockerfile (Default: ./Dockerfile)"
docker-context:
type: string
default: .
description: "The context for the Docker build (Default: .)"
build-args:
type: string
description: "List of additional build contexts (e.g., name=path)"
required: false
platforms:
type: string
description: "List of platforms for which to build the image"
default: linux/amd64,linux/arm64
registry:
type: string
default: ghcr.io
description: "The registry to push the image to (Default: ghcr.io)"

secrets:
registry-user:
required: false
registry-password:
required: false

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- dockerfile: ./webapp/Dockerfile
image: ghcr.io/ls1intum/Hephaestus/hephaestus-webapp
context: ./webapp
path: webapp
- dockerfile: ./server/intelligence-service/Dockerfile
image: ghcr.io/ls1intum/Hephaestus/hephaestus-intelligence-service
context: ./server/intelligence-service
path: server/intelligence-service
- dockerfile: ./server/webhook-ingest/Dockerfile
image: ghcr.io/ls1intum/Hephaestus/hephaestus-webhook-ingest
context: ./server/webhook-ingest
path: server/webhook-ingest
- build_method: nixpacks
dockerfile: ./server/application-server/.nixpacks/Dockerfile
image: ghcr.io/ls1intum/Hephaestus/hephaestus-application-server
context: ./server/application-server
path: server/application-server

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all

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

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ secrets.registry-user || github.actor }}
password: ${{ secrets.registry-password || secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.registry }}/${{ inputs.image-name }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
- name: Build and push Docker Image
if: matrix.build_method == 'dockerfile'
uses: docker/build-push-action@v6
with:
context: ${{ inputs.docker-context }}
file: ${{ inputs.docker-file }}
platforms: ${{ inputs.platforms }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: ${{ inputs.build-args }}
push: true
30 changes: 30 additions & 0 deletions server/application-server/.nixpacks/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM ghcr.io/railwayapp/nixpacks:ubuntu-1722297819

ENTRYPOINT ["/bin/bash", "-l", "-c"]
WORKDIR /app/


COPY .nixpacks/nixpkgs-59dc10b5a6f2a592af36375c68fda41246794b86.nix .nixpacks/nixpkgs-59dc10b5a6f2a592af36375c68fda41246794b86.nix
RUN nix-env -if .nixpacks/nixpkgs-59dc10b5a6f2a592af36375c68fda41246794b86.nix && nix-collect-garbage -d
RUN sudo apt-get update && sudo apt-get install -y --no-install-recommends wget

ARG NIXPACKS_JDK_VERSION=21
ARG NIXPACKS_METADATA=java

ENV NIXPACKS_JDK_VERSION=$NIXPACKS_JDK_VERSION NIXPACKS_METADATA=$NIXPACKS_METADATA

# setup phase
# noop

# build phase
COPY . /app/.
RUN --mount=type=cache,id=xE0e05wx0-m2/repository,target=/app/.m2/repository chmod +x ./mvnw
RUN --mount=type=cache,id=xE0e05wx0-m2/repository,target=/app/.m2/repository ./mvnw -DskipTests clean package




# start
COPY . /app
CMD ["java -Dserver.port=$PORT $JAVA_OPTS -jar target/*jar"]

1 change: 1 addition & 0 deletions server/application-server/.nixpacks/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build server/application-server -f server/application-server/.nixpacks/Dockerfile -t hephaestus-application-server --build-arg NIXPACKS_JDK_VERSION=21 --build-arg NIXPACKS_METADATA=java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ }:

let pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/59dc10b5a6f2a592af36375c68fda41246794b86.tar.gz") { overlays = [ ]; };
in with pkgs;
let
APPEND_LIBRARY_PATH = "${lib.makeLibraryPath [ ] }";
myLibraries = writeText "libraries" ''
export LD_LIBRARY_PATH="${APPEND_LIBRARY_PATH}:$LD_LIBRARY_PATH"
'';
in
buildEnv {
name = "59dc10b5a6f2a592af36375c68fda41246794b86-env";
paths = [
(runCommand "59dc10b5a6f2a592af36375c68fda41246794b86-env" { } ''
mkdir -p $out/etc/profile.d
cp ${myLibraries} $out/etc/profile.d/59dc10b5a6f2a592af36375c68fda41246794b86-env.sh
'')
jdk21 maven
];
}

0 comments on commit 2a7f34d

Please sign in to comment.