From 3c5ce73734545e4ab3a54f63bd684405ba980f9d Mon Sep 17 00:00:00 2001 From: dalbodeule <11470513+dalbodeule@users.noreply.github.com> Date: Thu, 13 Jun 2024 23:42:55 +0900 Subject: [PATCH] fix build.yml (x10) --- .github/workflows/build.yml | 38 +++++++++++++++++++--------- Dockerfile | 49 +++++++++++++------------------------ 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cb32bd5..7a3edf7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,25 +14,39 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up JDK 22 + uses: actions/setup-java@v2 + with: + distribution: 'oracle' + java-version: '22' + + - name: Build with Gradle + run: ./gradlew build + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Set datetime variable - id: vars - run: echo "DATETIME=$(date +'%Y%m%d%H%M')" >> $GITHUB_ENV - - name: Log in to Docker Hub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Create multi-platform image - run: | - docker buildx create --use - docker buildx build --platform linux/amd64,linux/arm64 \ - --tag dalbodeule/chzzkbot:${{ env.DATETIME }} \ - --tag dalbodeule/chzzkbot:latest \ - --push . \ No newline at end of file + - name: Set datetime variable + id: vars + run: echo "DATETIME=$(date +'%Y%m%d%H%M')" >> $GITHUB_ENV + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: | + ${{ secrets.DOCKER_USERNAME }}/chzzkbot:${{ env.DATETIME }} + ${{ secrets.DOCKER_USERNAME }}/chzzkbot:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ca8fbb2..80e14a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,42 +1,27 @@ -# Builder Stage -FROM ghcr.io/graalvm/graalvm-ce:22.3.3 AS builder +# Stage 1: Build the executable with GraalVM +FROM ghcr.io/graalvm/graalvm-ce:22.1.0 as build -# Set working directory WORKDIR /app -# Copy Gradle wrapper and build scripts -COPY gradlew ./ -COPY gradle ./gradle -COPY build.gradle.kts . -COPY settings.gradle.kts . -COPY gradle.properties . +# Install required dependencies +RUN gu install native-image -# Download dependencies -RUN ./gradlew --no-daemon dependencies +# Copy the Gradle files and source code +COPY build.gradle.kts settings.gradle.kts gradlew ./ +COPY gradle gradle +COPY src src -# Copy the source code -COPY src ./src +# Build the project +RUN ./gradlew build +RUN ./gradlew nativeImage -# Build the application -RUN ./gradlew nativeCompile +# Stage 2: Create a minimal Docker image and add the binary +FROM alpine:3.13 -# Runner Stage -FROM woahbase/alpine-glibc:latest AS runner - -# Install glibc (required for running Java applications on Alpine) -RUN apk add --no-cache libc6-compat patchelf - -# Set working directory WORKDIR /app -# Copy the native image from the builder stage -COPY --from=builder /app/build/native/nativeCompile/chzzk_bot . +# Copy the executable from the build stage +COPY --from=build /app/build/native-image/chzzk_bot . -# Ensure the application binary is executable -RUN chmod +x /app/chzzk_bot - -# Patch the binary to use the correct dynamic linker -RUN patchelf --set-interpreter /lib/ld-linux-x86-64.so.2 /app/chzzk_bot - -# Run the application -CMD ["./chzzk_bot"] \ No newline at end of file +# Set the entry point +ENTRYPOINT ["./chzzk_bot"] \ No newline at end of file