Skip to content

Commit

Permalink
Java ci (#8)
Browse files Browse the repository at this point in the history
* [java-ci]: updated ci

* [java-ci]: updated ci

* updated ci

* ci

* ci

* ci

* FIXED DOCKER
  • Loading branch information
vlaship authored Jan 21, 2024
1 parent 9a78120 commit ba2553a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
39 changes: 30 additions & 9 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: Java CI with Gradle

on:
- push
push:
branches:
- '*'
workflow_dispatch:

permissions:
contents: read
Expand All @@ -10,28 +13,46 @@ jobs:
build:

runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref != 'refs/heads/master'

steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

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

- name: Cache Gradle dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
${{ runner.os }}-gradle-
- name: Change wrapper permissions
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew clean build -x test
run: ./gradlew clean build -x test --no-daemon

docker-build:

needs: build

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build Docker image
uses: docker/build-push-action@v3
with:
context: .
file: ./jvm.Dockerfile
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ services:
DB_USER: ${DB_USER}
DB_PASS: ${DB_PASS}
DB_NAME: ${DB_NAME}
DB_SCHEMA: ${DB_SCHEMA}
SERVER_PORT: 18080
JWT_SECRET: ${JWT_SECRET}
JWT_TTL: ${JWT_TTL}
APP_NAME: ${APP_NAME}
19 changes: 10 additions & 9 deletions jvm.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
### Build stage
# Builder gradle
FROM gradle:jdk21-alpine AS builder
FROM azul/zulu-openjdk-alpine:21 AS builder

# Set the working directory inside the container
WORKDIR /app
WORKDIR /upacked

# Copy the source code into the container
COPY . .

# Build
RUN gradle clean unpack -x test
RUN ./gradlew clean unpack -x test

# Unpack the jar
ARG UNPACKED=build/unpacked
COPY ${UNPACKED}/BOOT-INF/lib /app/upacked/lib
COPY ${UNPACKED}/META-INF /app/upacked/META-INF
COPY ${UNPACKED}/BOOT-INF/classes /app/upacked

COPY ${UNPACKED}/BOOT-INF/lib /upacked/lib
COPY ${UNPACKED}/META-INF /upacked/META-INF
COPY ${UNPACKED}/BOOT-INF/classes /upacked

### Run stage
# Create a minimal production image
FROM azul/zulu-openjdk-alpine:21-jre-headless

# Set the working directory inside the container
WORKDIR /upacked
WORKDIR /

# Avoid running code as a root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser

# Copy only the necessary dirs and files from the builder stage
COPY --from=builder /app/upacked /upacked/app
COPY --from=builder /upacked ./app

# Run the binary when the container starts
CMD ["java", "-cp", "app:app/lib/*", "vlaship.backoffice.App"]
ENTRYPOINT ["java", "-cp", "app:app/lib/*", "dev.vlaship.backoffice.App"]

0 comments on commit ba2553a

Please sign in to comment.