diff --git a/.env.template b/.env.template index 0ad7ce3..4f28400 100644 --- a/.env.template +++ b/.env.template @@ -1,4 +1,7 @@ APP_PORT=3004 APP_ENV=development +APP_SERVICE_NAME=rpkm67-checkin DB_URL=postgres://root:1234@localhost:5432/rpkm67_db + +TRACER_ENDPOINT=localhost:4318 \ No newline at end of file diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/pull_request_template.md similarity index 89% rename from .github/PULL_REQUEST_TEMPLATE/pull_request_template.md rename to .github/pull_request_template.md index 7748e23..c38d93b 100644 --- a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +++ b/.github/pull_request_template.md @@ -3,6 +3,7 @@ - [ ]  New features - [ ]  Bug fixes - [ ]  Breaking changes +- [ ] Refactor ## Describe what you have done - ### New Features @@ -10,4 +11,4 @@ ### Fix - ### Others -- \ No newline at end of file +- diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml index ac5db1e..ac763ee 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-checkin 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 89% rename from .github/workflows/test-build.yml rename to .github/workflows/lint.yml index 7d24ab2..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 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 4c266a9..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/Makefile b/Makefile index a308874..87ffc20 100644 --- a/Makefile +++ b/Makefile @@ -16,10 +16,6 @@ docker: docker rm -v -f $$(docker ps -qa) || echo "No containers found. Skipping removal." docker-compose up -docker-qa: - docker rm -v -f $$(docker ps -qa) || echo "No containers found. Skipping removal." - docker-compose -f docker-compose.qa.yml up - server: go run cmd/main.go diff --git a/docker-compose.qa.template.yml b/docker-compose.qa.template.yml deleted file mode 100644 index 7c14e5e..0000000 --- a/docker-compose.qa.template.yml +++ /dev/null @@ -1,176 +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: host.docker.internal:3004 - SERVICE_STORE: store: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" - - otel-collector: - image: otel/opentelemetry-collector-contrib:0.104.0 - command: ["--config=/etc/opentelemetry.yml"] - volumes: - - ./microservices/opentelemetry/opentelemetry.yml:/etc/opentelemetry.yml - ports: - - 4317:4317 # OTLP gRPC receiver - - 4318:4318 # OTLP HTTP receiver - networks: - - rpkm67 - depends_on: - - jaeger - - jaeger: - image: jaegertracing/all-in-one:1.58 - environment: - - COLLECTOR_OTLP_ENABLED=true - ports: - - 9091:16686 # Jaeger UI - - 14250:14250 # Jaeger gRPC collector - - 14268:14268 # Jaeger HTTP collector - networks: - - rpkm67 - -networks: - rpkm67: - name: rpkm67