From b53805ee3fb5e022c586dccdfac432df47661225 Mon Sep 17 00:00:00 2001 From: Ksan Date: Wed, 10 Jun 2026 18:03:56 +0200 Subject: [PATCH] testing new ci/cd --- .gitea/workflows/ci.yaml | 103 +++++++++++++++--- .gitignore | 1 + backend/Dockerfile | 5 + .../config/FirebaseConfig.java | 2 +- ci-full.yaml | 24 ++++ 5 files changed, 121 insertions(+), 14 deletions(-) create mode 100644 backend/Dockerfile create mode 100644 ci-full.yaml diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 423bf7d..1aeb9d0 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -1,29 +1,106 @@ -name: CI +name: CI/CD on: push: - branches: [dev] + branches: + - dev + - main + pull_request: - branches: [main] + branches: + - main + +env: + JAVA_VERSION: "21" jobs: - backend-tests: + backend-unit-tests: + name: Backend Unit Tests runs-on: ubuntu-latest + defaults: run: working-directory: backend - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-java@v4 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK ${{ env.JAVA_VERSION }} + uses: actions/setup-java@v4 with: - java-version: '21' - distribution: 'temurin' + distribution: temurin + java-version: ${{ env.JAVA_VERSION }} - name: Make Gradle wrapper executable - run: chmod +x ./gradlew + run: chmod +x gradlew - - name: Run tests - run: ./gradlew test --no-daemon + - name: Run unit tests + run: ./gradlew test - # TODO: CD logic — deploy after successful tests on merge to main + deploy: + name: Deploy + needs: backend-unit-tests + + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK ${{ env.JAVA_VERSION }} + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: ${{ env.JAVA_VERSION }} + + - name: Build boot jar + working-directory: backend + run: | + chmod +x gradlew + ./gradlew bootJar + + - name: Stage jar for Docker + working-directory: backend + run: | + BOOT_JAR=$(find build/libs -name "*.jar" ! -name "*-plain.jar" | head -n 1) + cp "$BOOT_JAR" app.jar + + - name: Login to Docker registry + run: | + echo "${{ secrets.REGISTRY_PASSWORD }}" | \ + docker login git.${{ secrets.DOMAIN }} \ + -u "${{ secrets.REGISTRY_USER }}" \ + --password-stdin + + - name: Build Docker image + run: | + docker build \ + -t git.${{ secrets.DOMAIN }}/${{ secrets.REGISTRY_USER }}/etf-oglasi-server:latest \ + backend/ + + - name: Push Docker image + run: | + docker push \ + git.${{ secrets.DOMAIN }}/${{ secrets.REGISTRY_USER }}/etf-oglasi-server:latest + + - name: Deploy to VPS + run: | + mkdir -p ~/.ssh + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/key + chmod 600 ~/.ssh/key + ssh-keyscan -H "${{ secrets.DEPLOY_HOST }}" >> ~/.ssh/known_hosts + + # Write secrets to VPS (only if they've changed or first deploy) + ssh -i ~/.ssh/key "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \ + "mkdir -p ~/programs/etf-oglasi-server/config" + + + echo "${{ secrets.FIREBASE_CREDENTIALS }}" | \ + ssh -i ~/.ssh/key "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \ + "cat > ~/programs/etf-oglasi-server/config/firebase.json" + + ssh -i ~/.ssh/key "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \ + "cd ~/programs/etf-oglasi-server && docker compose pull && docker compose up -d" diff --git a/.gitignore b/.gitignore index 85b4e10..f3e878f 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ backend/**/*temp.java backend/src/main/resources/google-services.json backend/src/main/resources/etf-oglasi-firebase.json +backend/src/main/resources/firebase.json # Java / Eclipse / STS .classpath diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..dcc36fa --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,5 @@ +FROM eclipse-temurin:21-jre-jammy +WORKDIR /app +COPY app.jar app.jar +EXPOSE 8080 +ENTRYPOINT ["java", "-jar", "/app/app.jar"] diff --git a/backend/src/main/java/dev/ksan/etfoglasiserver/config/FirebaseConfig.java b/backend/src/main/java/dev/ksan/etfoglasiserver/config/FirebaseConfig.java index f2efcef..cdc5b1c 100644 --- a/backend/src/main/java/dev/ksan/etfoglasiserver/config/FirebaseConfig.java +++ b/backend/src/main/java/dev/ksan/etfoglasiserver/config/FirebaseConfig.java @@ -17,7 +17,7 @@ public class FirebaseConfig { @Bean public FirebaseApp firebaseApp() throws IOException { GoogleCredentials credentials = GoogleCredentials - .fromStream(new ClassPathResource("etf-oglasi-firebase.json").getInputStream()) + .fromStream(new ClassPathResource("firebase.json").getInputStream()) .createScoped(List.of("https://www.googleapis.com/auth/firebase.messaging")); FirebaseOptions options = FirebaseOptions.builder() diff --git a/ci-full.yaml b/ci-full.yaml new file mode 100644 index 0000000..8c644a7 --- /dev/null +++ b/ci-full.yaml @@ -0,0 +1,24 @@ +name: CI - full + +on: + pull_request: + branches: [main] + +jobs: + backend-test: + uses: ./.gitea/workflows/backend-test.yaml + + frontend-build: + runs-on: ubuntu-latest + defaults: + run: + working-directory: frontend + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Install dependencies + run: npm ci + - name: Build frontend + run: npx expo export --platform web