From 08402a63f2493886cbfb0a60acd6abdf2dc9fddf Mon Sep 17 00:00:00 2001 From: quytranDF Date: Sun, 8 Sep 2024 15:42:10 +0700 Subject: [PATCH] debug --- .circleci/config.yml | 47 +++++++++++------------ .github/workflows/build-workflow.yml | 5 +-- .github/workflows/deploy-dev-workflow.yml | 7 ++-- 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e256b45..92a3927 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -42,9 +42,12 @@ jobs: machine: image: ubuntu-2004:current working_directory: ~/map-sorter-api + environment: + DOCKER_IMAGE: high10hunter/map-sorter-api + DOCKER_TAG: latest steps: - aws-cli/setup: - role-arn: 'arn:aws:iam::AWS_ACCOUNT_ID:role/circleci-oidc-provider-aws' + role-arn: 'arn:aws:iam::${AWS_ACCOUNT_ID}:role/circleci-oidc-provider-aws' aws-region: AWS_REGION - checkout @@ -53,36 +56,30 @@ jobs: - 'SHA256:+2S1UpsWHcjQu4ur9jpqF16GQa9NrND9qbFNU6pzB64' - run: - name: Create .env file + name: Create .env file and sync to dev server command: | cd tools aws ssm get-parameters-by-path --path "/dev" --with-decryption --recursive > mapsorter_env.json ./convert_ssm_params_to_dotenv.sh mapsorter_env.json + scp -oStrictHostKeyChecking=no -v -r .env $SSH_USER@$SSH_HOST:/home/gdsc/map-sorter-api/.env - run: - name: Sync .env file to dev server - command: | - scp -oStrictHostKeyChecking=no -r .env $SSH_USER@$SSH_HOST:~/map-sorter-api - - - run: - name: SSH into dev server + name: SSH into dev server and deploy command: | echo "SSH into dev server" - ssh -oStrictHostKeyChecking=no -v $SSH_USER@$SSH_HOST - - - run: - name: Login to DockerHub - command: echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - - - run: - name: 'Deploy to << pipeline.parameters.build_stage >> environment' - command: | - echo "Deploying to << pipeline.parameters.build_stage >>" - docker pull $DOCKER_IMAGE:$DOCKER_TAG - docker container stop map-sorter-api || true - docker container rm map-sorter-api || true - docker run --log-opt max-size=10m --log-opt max-file=3 --log-opt compress=true --name map-sorter-api -d --env-file .env $DOCKER_IMAGE:$DOCKER_TAG - docker image prune --all -f + ssh -o StrictHostKeyChecking=no -v $SSH_USER@$SSH_HOST " + su - gdsc -c ' + cd map-sorter-api && + echo \"$DOCKER_PASSWORD\" | docker login -u \"$DOCKER_USERNAME\" --password-stdin && + docker pull $DOCKER_IMAGE:$DOCKER_TAG && + docker container stop map-sorter-api || true && + docker container rm map-sorter-api || true && + docker run --log-opt max-size=10m --log-opt max-file=3 --log-opt compress=true \ + --name map-sorter-api -d --env-file .env $DOCKER_IMAGE:$DOCKER_TAG && + docker image prune --all -f + rm .env + ' + " workflows: version: 3 @@ -94,7 +91,7 @@ workflows: - build: filters: branches: - only: test + only: develop DeployDev: # if the 'task' parameter equals 'deploy' @@ -111,7 +108,7 @@ workflows: - build filters: branches: - only: test + only: develop DeployProd: # if the 'task' parameter equals 'deploy' diff --git a/.github/workflows/build-workflow.yml b/.github/workflows/build-workflow.yml index 6201318..c88751a 100644 --- a/.github/workflows/build-workflow.yml +++ b/.github/workflows/build-workflow.yml @@ -2,8 +2,7 @@ name: Build on: pull_request: types: [opened, synchronize] - # branches: [develop] - branches: [test] + branches: [develop] jobs: build: runs-on: ubuntu-latest @@ -15,5 +14,5 @@ jobs: -X POST \ -H "Content-Type: application/json" \ -H "Circle-Token: ${{ secrets.CIRCLECI_TOKEN }}" \ - --data '{"branch": "test", "parameters": {"task": "build"}}' \ + --data '{"branch": "develop", "parameters": {"task": "build"}}' \ https://circleci.com/api/v2/project/gh/dscdut/map-sorter-api/pipeline diff --git a/.github/workflows/deploy-dev-workflow.yml b/.github/workflows/deploy-dev-workflow.yml index 75b9b4a..ca6f827 100644 --- a/.github/workflows/deploy-dev-workflow.yml +++ b/.github/workflows/deploy-dev-workflow.yml @@ -2,12 +2,11 @@ name: DeployDev on: pull_request: types: [closed] - # branches: [develop] - branches: [test] + branches: [develop] jobs: deploy: - if: ${{ github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'test' }} + if: ${{ github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop' }} runs-on: ubuntu-latest steps: @@ -18,5 +17,5 @@ jobs: -X POST \ -H "Content-Type: application/json" \ -H "Circle-Token: ${{ secrets.CIRCLECI_TOKEN }}" \ - --data '{"branch": "test", "parameters": {"task": "deploy", "build_stage": "dev"}}' \ + --data '{"branch": "develop", "parameters": {"task": "deploy", "build_stage": "dev"}}' \ https://circleci.com/api/v2/project/gh/dscdut/map-sorter-api/pipeline