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
90 changes: 90 additions & 0 deletions .github/workflows/gradle-ghcr-cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Java CI CD

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

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

- name: Set up Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582

- name: Build with Gradle
run: ./gradlew build

dependency-submission:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4

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

- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582

push-to-ghcr:
name: Push image to ghcr
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' || github.event_name == 'release'
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- uses: actions/checkout@v4

- name: Log in to container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest
type=semver,pattern={{version}}

- name: Build and push image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Generate attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
43 changes: 0 additions & 43 deletions .github/workflows/gradle.yml

This file was deleted.

25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2025 Dan Sirbu
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
FROM gradle:jdk21 AS build
WORKDIR /app
COPY build.gradle ./build.gradle
COPY gradle ./gradle
COPY gradlew ./gradlew
COPY settings.gradle ./settings.gradle
RUN chmod +x ./gradlew

# Download dependencies
RUN ./gradlew dependencies

# Copy source code and build jar
COPY src ./src
RUN ./gradlew bootJar

FROM eclipse-temurin:21-jdk
WORKDIR /app
COPY --from=build /app/build/libs/*.jar ./app.jar
EXPOSE 8080

ENTRYPOINT [ "java", "-jar", "./app.jar" ]
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ Here is a short guide on how to run this project on your pc:
Inside the root directory of the project run
``.\gradlew bootRun --args='--spring.profiles.active=dev'``.
This command starts the backend with the dev profile active
## Using the docker container
In order to use the docker container, you only need docker installed.
First you have to build image with ``docker build -t simple-store:latest .``

And then run the image, while defining the needed environment variables (see [.env.template](.env.template)).
Any arguments added to the end will be appended to the program (useful for setting spring boot profiles)
### Running using .env file
If you have an .env file, then in order to run the container just do
``docker run --name simple-store-backend --env-file LOCATION_OF_ENV_FILE -p 8080:8080 simple-store:latest``
## Running without .env file
If you do not have an .env file, then you will have to define all the needed environment variables yourself.
Here is how to run the container without an .env file:
``docker run --name simple-store-backend -e ENV_VAR1=VAL1 -e ENV_VAR2=VAL2 ... -p 8080:8080 simple-store:latest``

# 📡 API Documentation
- The API is documented using **Swagger**
Expand Down
Loading