From 601f03276386d2044a0a463cc711475d7e1206af Mon Sep 17 00:00:00 2001 From: Muhammad Raihan Akbar <ianakbar711@gmail.com> Date: Fri, 14 Feb 2025 19:24:20 +0700 Subject: [PATCH] ci: add ci configurations --- .github/workflows/dev-ci.yml | 37 +++++++++++++++++++ .github/workflows/production-cd.yml | 53 +++++++++++++++++++++++++++ .github/workflows/staging-ci-cd.yml | 55 +++++++++++++++++++++++++++++ Dockerfile | 2 +- 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/dev-ci.yml create mode 100644 .github/workflows/production-cd.yml create mode 100644 .github/workflows/staging-ci-cd.yml diff --git a/.github/workflows/dev-ci.yml b/.github/workflows/dev-ci.yml new file mode 100644 index 0000000..ec85313 --- /dev/null +++ b/.github/workflows/dev-ci.yml @@ -0,0 +1,37 @@ +name: CI - Development + +on: + push: + branches: + - dev + pull_request: + branches: + - dev + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up JDK 21 (using Zulufx) + uses: actions/setup-java@v2 + with: + java-version: '21' + distribution: 'zulu' + java-package: jdk + architecture: x64 + + - name: Build with Maven + run: mvn clean install + + - name: Run Unit Tests + run: mvn test + + - name: Run Integration Tests + run: mvn verify -P integration-tests + + - name: Run UAT (Karate DSL) + run: mvn test -P uat \ No newline at end of file diff --git a/.github/workflows/production-cd.yml b/.github/workflows/production-cd.yml new file mode 100644 index 0000000..1e4a411 --- /dev/null +++ b/.github/workflows/production-cd.yml @@ -0,0 +1,53 @@ +name: CI/CD Pipeline for GKE + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Install the gcloud CLI + uses: google-github-actions/setup-gcloud@v2 + with: + project_id: ${{ secrets.GOOGLE_PROJECT }} + service_account_key: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} + export_default_credentials: true + + - name: Authenticate with GCP + uses: google-github-actions/auth@v1 + with: + credentials_json: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} + + - name: Configure Docker + run: | + gcloud auth configure-docker + + - name: Build and Push Docker Image + env: + GOOGLE_PROJECT: ${{ secrets.GOOGLE_PROJECT }} + run: | + gcloud auth configure-docker us-central1-docker.pkg.dev + docker build -t us-central1-docker.pkg.dev/$GOOGLE_PROJECT/my-repository/authentication:latest . + docker push us-central1-docker.pkg.dev/$GOOGLE_PROJECT/my-repository/authentication:latest + + - name: Install required components + run: | + gcloud components update + gcloud components install gke-gcloud-auth-plugin + + - name: Deploy to GKE + env: + GOOGLE_PROJECT: ${{ secrets.GOOGLE_PROJECT }} + run: | + gcloud container clusters get-credentials safetypin-cluster --region asia-southeast2 + sed -i "s/GOOGLE_PROJECT/$GOOGLE_PROJECT/g" resources.yaml + kubectl apply -f resources.yaml \ No newline at end of file diff --git a/.github/workflows/staging-ci-cd.yml b/.github/workflows/staging-ci-cd.yml new file mode 100644 index 0000000..ccc2d24 --- /dev/null +++ b/.github/workflows/staging-ci-cd.yml @@ -0,0 +1,55 @@ +name: CI/CD Pipeline for Staging + +on: + push: + branches: + - staging + pull_request: + branches: + - staging + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up JDK 21 (using Zulufx) + uses: actions/setup-java@v2 + with: + java-version: '21' + distribution: 'zulu' + java-package: jdk + architecture: x64 + + - name: Build with Maven + run: mvn clean install + + - name: Run Unit Tests + run: mvn test + + - name: Run Regression Tests (JUnit 5, TestContainers) + run: mvn test -P regression-tests + + build-and-deliver: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Install the gcloud CLI + uses: google-github-actions/setup-gcloud@v0 + with: + project_id: ${{ secrets.GOOGLE_PROJECT }} + service_account_key: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} + export_default_credentials: true + + - name: Build and Push Docker Image + env: + GOOGLE_PROJECT: ${{ secrets.GOOGLE_PROJECT }} + run: | + gcloud auth configure-docker us-central1-docker.pkg.dev + docker build -t us-central1-docker.pkg.dev/$GOOGLE_PROJECT/my-repository/authentication:latest . + docker push us-central1-docker.pkg.dev/$GOOGLE_PROJECT/my-repository/authentication:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4e6ecfe..a5403ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,6 @@ RUN mvn clean package -DskipTests # Step 2: Use OpenJDK 21 to run the application FROM openjdk:21-jdk-slim WORKDIR /app -COPY --from=builder /app/target/api-gateway-0.0.1-SNAPSHOT.jar app.jar +COPY --from=builder /app/target/authentication-0.0.1-SNAPSHOT.jar app.jar EXPOSE 8080 CMD ["java", "-jar", "app.jar"] -- GitLab