diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..d11b61d --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,85 @@ +name: CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + packages: write + +env: + REGISTRY: ghcr.io + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "17" + cache: gradle + + - name: Copy application.yml into runner + run: | + mkdir -p src/main/resources + echo "${{ secrets.APPLICATION_YML }}" > src/main/resources/application.yml + + - name: Build + Test(Gradle) + if: ${{ hashFiles('**/build.gradle*') != '' }} + run: | + chmod +x ./gradlew + ./gradlew clean test + ./gradlew bootJar + JAR=$(ls build/libs/*.jar | head -n 1) + cp "$JAR" app.jar + + - name: Compute image name (change to lowercase) + id: img + run: echo "name=${{ env.REGISTRY }}/${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GHCR_TOKEN }} + + - name: Extract Docker metadata (tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ steps.img.outputs.name }} + tags: | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} + type=ref,event=tag + type=sha + + - name: Set up Docker Build + uses: docker/setup-buildx-action@v3 + + - name: Debug paths + run: | + pwd + ls -la + find . -maxdepth 3 -iname 'Dockerfile' -print + + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5dca8d3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM eclipse-temurin:17-jre-alpine +WORKDIR /app +COPY app.jar app.jar +EXPOSE 8080 +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file