From 433ecd7003f5ff25bab088974889875dc0a0c963 Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Fri, 12 Jul 2024 23:23:45 +0700 Subject: [PATCH] new wk --- .../pull_request_template.md | 21 --- .github/pull_request_template.md | 14 ++ .github/workflows/build-deploy.yml | 61 ++++++- .../workflows/{test-build.yml => lint.yml} | 8 +- .../{run-unit-test.yml => unit-test.yml} | 13 +- docker-compose.qa.template.yml | 152 ------------------ 6 files changed, 81 insertions(+), 188 deletions(-) delete mode 100644 .github/PULL_REQUEST_TEMPLATE/pull_request_template.md create mode 100644 .github/pull_request_template.md rename .github/workflows/{test-build.yml => lint.yml} (84%) rename .github/workflows/{run-unit-test.yml => unit-test.yml} (86%) delete mode 100644 docker-compose.qa.template.yml diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md deleted file mode 100644 index 3833a16..0000000 --- a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +++ /dev/null @@ -1,21 +0,0 @@ -## Change made - -- [ ] New features -- [ ] Bug fixes -- [ ] Breaking changes - -## Describe what you have done - -- - -### New Features - -- - -### Fix - -- - -### Others - -- diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..c38d93b --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,14 @@ +## Change made + +- [ ]  New features +- [ ]  Bug fixes +- [ ]  Breaking changes +- [ ] Refactor +## Describe what you have done +- +### New Features +- +### Fix +- +### Others +- diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml index ac5db1e..db600c6 100644 --- a/.github/workflows/build-deploy.yml +++ b/.github/workflows/build-deploy.yml @@ -2,27 +2,47 @@ name: Build on: workflow_dispatch: - push: + pull_request: + types: + - closed branches: - main - dev - tags: - - v* env: + SERVICE_NAME: rpkm67-store IMAGE_NAME: ghcr.io/${{ github.repository }} - IMAGE_TAG: ${{ github.sha }} + IMAGE_TAG: jobs: build: name: Build runs-on: ubuntu-latest + if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' + outputs: + IMAGE_TAG: ${{ steps.tag_action.outputs.new_tag }} permissions: - contents: read + contents: write packages: write steps: + - uses: actions/checkout@v4 + with: + fetch-depth: '0' + + - name: Bump version and push tag + uses: anothrNick/github-tag-action@1.64.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: true + RELEASE_BRANCHES: dev + DEFAULT_BUMP: patch + id: tag_action + + - name: Set IMAGE_TAG + run: echo "IMAGE_TAG=${{ steps.tag_action.outputs.new_tag }}" >> $GITHUB_ENV + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -40,5 +60,34 @@ jobs: tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }},${{ env.IMAGE_NAME }}:latest cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max + + cd: + name: Continuous Deployment + needs: build + runs-on: ubuntu-latest + env: + IMAGE_TAG: ${{ needs.build.outputs.IMAGE_TAG }} -# docker pull --platform linux/x86_64 \ No newline at end of file + steps: + - name: Checkout DevOps repository + uses: actions/checkout@v4 + with: + repository: isd-sgcu/rpkm67-devops + token: ${{ secrets.RPKM67_DEVOPS_TOKEN }} + + - name: Update image tag in dev + uses: mikefarah/yq@master + with: + cmd: yq -i '.[0].value = "${{ env.IMAGE_NAME }}:" + strenv(IMAGE_TAG)' isd/${{ env.SERVICE_NAME }}/deployment.yaml + + - name: Update image tag in prod + uses: mikefarah/yq@master + if: github.ref == 'refs/heads/main' + with: + cmd: yq -i '.[0].value = "${{ env.IMAGE_NAME }}:" + strenv(IMAGE_TAG)' prod/${{ env.SERVICE_NAME }}/deployment.yaml + + - name: Commit & Push changes + uses: actions-js/push@v1.4 + with: + repository: isd-sgcu/rpkm67-devops + github_token: ${{ secrets.RPKM67_DEVOPS_TOKEN }} diff --git a/.github/workflows/test-build.yml b/.github/workflows/lint.yml similarity index 84% rename from .github/workflows/test-build.yml rename to .github/workflows/lint.yml index 762f358..ffba9ce 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/lint.yml @@ -1,13 +1,17 @@ name: Lint on: + workflow_dispatch: + pull_request: + branches: + - main + - dev push: branches: - main - dev tags: - v* - pull_request: permissions: contents: read @@ -24,7 +28,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: "1.22.4" + go-version: '1.22.4' cache: false - name: golangci-lint uses: golangci/golangci-lint-action@v3 diff --git a/.github/workflows/run-unit-test.yml b/.github/workflows/unit-test.yml similarity index 86% rename from .github/workflows/run-unit-test.yml rename to .github/workflows/unit-test.yml index f5be40f..e0696c9 100644 --- a/.github/workflows/run-unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -1,18 +1,17 @@ -name: "Pull request/Push: Run unit test" +name: Unit Tests on: + workflow_dispatch: pull_request: branches: - - dev - - master - main - - beta + - dev push: branches: - - dev - - master - main - - beta + - dev + tags: + - v* jobs: build: diff --git a/docker-compose.qa.template.yml b/docker-compose.qa.template.yml deleted file mode 100644 index c8e39db..0000000 --- a/docker-compose.qa.template.yml +++ /dev/null @@ -1,152 +0,0 @@ -version: "3.9" - -services: - gateway: - image: ghcr.io/isd-sgcu/rpkm67-gateway:latest - container_name: gateway - restart: unless-stopped - environment: - APP_PORT: 3001 - APP_ENV: development - APP_MAX_FILE_SIZE_MB: 10 - CORS_ORIGINS: http://localhost:3000 - SERVICE_AUTH: auth:3002 - SERVICE_BACKEND: backend:3003 - SERVICE_CHECKIN: checkin:3004 - SERVICE_STORE: host.docker.internal:3005 - networks: - - rpkm67 - ports: - - "3001:3001" - - auth: - image: ghcr.io/isd-sgcu/rpkm67-auth:latest - container_name: auth - restart: unless-stopped - environment: - APP_PORT: 3002 - APP_ENV: development - DB_URL: postgres://root:1234@db:5432/rpkm67_db - REDIS_HOST: cache - REDIS_PORT: 6379 - REDIS_PASSWORD: 5678 - JWT_SECRET: secret - JWT_ACCESS_TTL: 3600 - JWT_REFRESH_TTL: 259200 - JWT_ISSUER: rpkm67.sgcu.in.th - JWT_RESET_TOKEN_TTL: 900 - OAUTH_CLIENT_ID: client_id - OAUTH_CLIENT_SECRET: client_secret - OAUTH_REDIRECT_URI: http://localhost:3000 - networks: - - rpkm67 - volumes: - - ./microservices/auth:/app/config/staffs - ports: - - "3002:3002" - - backend: - image: ghcr.io/isd-sgcu/rpkm67-backend:latest - container_name: backend - restart: unless-stopped - environment: - APP_PORT: 3003 - APP_ENV: development - DB_URL: postgres://root:1234@db:5432/rpkm67_db - REDIS_HOST: cache - REDIS_PORT: 6379 - REDIS_PASSWORD: 5678 - PIN_WORKSHOP_CODE: workshop - PIN_WORKSHOP_COUNT: 5 - PIN_LANDMARK_CODE: landmark - PIN_LANDMARK_COUNT: 4 - networks: - - rpkm67 - ports: - - "3003:3003" - - checkin: - image: ghcr.io/isd-sgcu/rpkm67-checkin:latest - container_name: checkin - restart: unless-stopped - environment: - APP_PORT: 3004 - APP_ENV: development - DB_URL: postgres://root:1234@db:5432/rpkm67_db - networks: - - rpkm67 - ports: - - "3004:3004" - - # store: - # image: ghcr.io/isd-sgcu/rpkm67-store:latest - # container_name: store - # restart: unless-stopped - # environment: - # APP_PORT: 3005 - # APP_ENV: development - # APP_MAX_FILE_SIZE_MB: 20 - # STORE_ENDPOINT: endpoint - # STORE_ACCESS_KEY: access_key - # STORE_SECRET_KEY: secret_key - # STORE_USE_SSL: true - # STORE_BUCKET_NAME: rpkm67-local - # networks: - # - rpkm67 - # ports: - # - "3005:3005" - - db: - image: postgres:15.1-alpine3.17 - container_name: db - restart: unless-stopped - environment: - POSTGRES_USER: root - POSTGRES_PASSWORD: "1234" - POSTGRES_DB: rpkm67_db - networks: - - rpkm67 - volumes: - - ./volumes/postgres:/var/lib/postgresql/data - ports: - - "5432:5432" - - cache: - image: redis:7.2.3-alpine - container_name: cache - restart: unless-stopped - environment: - REDIS_HOST: localhost - REDIS_PASSWORD: "5678" - networks: - - rpkm67 - ports: - - "6379:6379" - - prometheus: - image: prom/prometheus:latest - container_name: prometheus - restart: unless-stopped - networks: - - rpkm67 - volumes: - - ./microservices/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml - ports: - - "9090:9090" - - grafana: - image: grafana/grafana:latest - container_name: grafana - restart: unless-stopped - environment: - - GF_SECURITY_ADMIN_PASSWORD=1234 - networks: - - rpkm67 - volumes: - - ./volumes/grafana:/var/lib/grafana - ports: - - "3006:3000" - -networks: - rpkm67: - name: rpkm67