Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
65 changes: 65 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Docker CI

on:
release:
types: [ 'published' ]

env:
TARGET_PLATFORM: linux/amd64,linux/arm64
REGISTRY: ghcr.io

jobs:
maven-build:
uses: ./.github/workflows/maven.yml

docker-build-publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
needs:
- maven-build
steps:
- name: Checkout repository
uses: actions/checkout@v4

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

- name: Set lowercase repository name
run: echo "REPO_LC=${GITHUB_REPOSITORY@L}" >> $GITHUB_ENV

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.REPO_LC }}
tags: |
type=semver,pattern={{raw}}

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

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

- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: staging/

- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: ${{ env.TARGET_PLATFORM }}
12 changes: 6 additions & 6 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: maven

- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Copy Artifact
run: mkdir staging && cp -p target/*.jar staging
run: mkdir staging && cp -p target/*.jar staging/codespark-backend.jar

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: codespark-backend
path: staging
path: staging/
retention-days: 1

- name: Update dependency graph
Expand Down
22 changes: 8 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
# Use an official Maven image to build the project
FROM maven:3.9.6-eclipse-temurin-21 AS build
# Use Java slim image
FROM openjdk:21-slim

# Copy all the code into the image
COPY . .
# Set workdir
WORKDIR /app

# Build the Spring Boot application
RUN mvn clean package -DskipTests

# Use JRE image to run the application
FROM eclipse-temurin:21-jre

# Copy the built JAR from the build stage
COPY --from=build /target/*.jar app.jar
# Copy the java file
COPY staging/codespark-backend.jar .

# Expose port 8080 for the application
EXPOSE 8080

# Run the application
ENTRYPOINT ["java", "-jar", "app.jar"]
# Set default command to run the bot
CMD ["java", "-jar", "codespark-backend.jar"]
8 changes: 8 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
codespark-backend:
container_name: codespark-backend
image: ghcr.io/codesparkapp/api:latest
ports:
- "8080:8080"
restart: always
env_file: stack.env