From d51de01eaac49aa2fe1a9e3141576454f30691fb Mon Sep 17 00:00:00 2001 From: abwarten Date: Mon, 12 Aug 2024 11:24:10 +0900 Subject: [PATCH] Init --- .github/workflows/ci-cd-dev.yml | 66 +++++++++++++++++++++++++++++++++ .github/workflows/ci-cd-prd.yml | 66 +++++++++++++++++++++++++++++++++ Dockerfile | 25 +++++++++++++ gradle.properties | 3 ++ settings.gradle | 2 +- 5 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci-cd-dev.yml create mode 100644 .github/workflows/ci-cd-prd.yml create mode 100644 Dockerfile create mode 100644 gradle.properties diff --git a/.github/workflows/ci-cd-dev.yml b/.github/workflows/ci-cd-dev.yml new file mode 100644 index 0000000..fdf94f6 --- /dev/null +++ b/.github/workflows/ci-cd-dev.yml @@ -0,0 +1,66 @@ +name: DEV CI/CD Pipeline + +on: + push: + branches: + - dev + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4.1.7 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.5.0 + + - name: Cache Docker layers + uses: actions/cache@v4.0.2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Log in to Google Cloud + uses: google-github-actions/auth@v2.1.3 + with: + credentials_json: ${{ secrets.GCP_CREDENTIALS }} + + - name: Configure docker for gcloud + run: gcloud auth configure-docker asia-northeast3-docker.pkg.dev + + - name: Build and push Docker image + run: | + docker buildx build --push \ + --tag asia-northeast3-docker.pkg.dev/code-review-platform-flow/flow-dev/flow-admin-main-dev:${{ github.sha }} . + + deploy: + runs-on: ubuntu-latest + needs: build + + steps: + - name: Checkout deployment repo + uses: actions/checkout@v4.1.7 + with: + repository: code-review-platform-flow/flow-manifest + path: manifests + token: ${{ secrets.FLOW_DEPLOY_KEY }} + + - name: List files for debugging + run: ls -R + + - name: Update manifest + run: | + sed -i "s|image: .*|image: asia-northeast3-docker.pkg.dev/code-review-platform-flow/flow-dev/flow-admin-main-dev:${{ github.sha }}|" manifests/flow-admin-main-dev/deployment.yaml + + - name: Commit and push changes + working-directory: manifests + run: | + git config --global user.name 'github-actions' + git config --global user.email 'github-actions@github.com' + git add . + git commit -m "Update image to asia-northeast3-docker.pkg.dev/code-review-platform-flow/flow-dev/flow-admin-main-dev:${{ github.sha }}" + git push diff --git a/.github/workflows/ci-cd-prd.yml b/.github/workflows/ci-cd-prd.yml new file mode 100644 index 0000000..348db3a --- /dev/null +++ b/.github/workflows/ci-cd-prd.yml @@ -0,0 +1,66 @@ +name: DEV CI/CD Pipeline + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4.1.7 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.5.0 + + - name: Cache Docker layers + uses: actions/cache@v4.0.2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Log in to Google Cloud + uses: google-github-actions/auth@v2.1.3 + with: + credentials_json: ${{ secrets.GCP_CREDENTIALS }} + + - name: Configure docker for gcloud + run: gcloud auth configure-docker asia-northeast3-docker.pkg.dev + + - name: Build and push Docker image + run: | + docker buildx build --push \ + --tag asia-northeast3-docker.pkg.dev/code-review-platform-flow/flow-prd/flow-admin-main-prd:${{ github.sha }} . + + deploy: + runs-on: ubuntu-latest + needs: build + + steps: + - name: Checkout deployment repo + uses: actions/checkout@v4.1.7 + with: + repository: code-review-platform-flow/flow-manifest + path: manifests + token: ${{ secrets.FLOW_DEPLOY_KEY }} + + - name: List files for debugging + run: ls -R + + - name: Update manifest + run: | + sed -i "s|image: .*|image: asia-northeast3-docker.pkg.dev/code-review-platform-flow/flow-prd/flow-admin-main-prd:${{ github.sha }}|" manifests/flow-admin-main-prd/deployment.yaml + + - name: Commit and push changes + working-directory: manifests + run: | + git config --global user.name 'github-actions' + git config --global user.email 'github-actions@github.com' + git add . + git commit -m "Update image to asia-northeast3-docker.pkg.dev/code-review-platform-flow/flow-prd/flow-admin-main-prd:${{ github.sha }}" + git push diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2ff5f9c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# builder image +FROM amazoncorretto:17-al2-jdk AS builder + +RUN mkdir /flow-admin-main +WORKDIR /flow-admin-main + +COPY . . + +RUN chmod +x gradlew +RUN ./gradlew clean bootJar + +# runtime image +FROM amazoncorretto:17.0.12-al2 + +ENV TZ=Asia/Seoul +ENV PROFILE=${PROFILE} + +RUN mkdir /flow-admin-main +WORKDIR /flow-admin-main + +COPY --from=builder /flow-admin-main/build/libs/flow-admin-main-* /flow-admin-main/app.jar + +CMD ["sh", "-c", " \ + java -Dspring.profiles.active=${PROFILE} \ + -jar /flow-admin-main/app.jar"] diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..8c97b3e --- /dev/null +++ b/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.daemon=true +org.gradle.parallel=true +org.gradle.configureondemand=true \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index e83a19c..7bef29d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'admin' +rootProject.name = 'main'