Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
quytranDF committed Sep 8, 2024
1 parent e8dfa77 commit 08402a6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
47 changes: 22 additions & 25 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -94,7 +91,7 @@ workflows:
- build:
filters:
branches:
only: test
only: develop

DeployDev:
# if the 'task' parameter equals 'deploy'
Expand All @@ -111,7 +108,7 @@ workflows:
- build
filters:
branches:
only: test
only: develop

DeployProd:
# if the 'task' parameter equals 'deploy'
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: Build
on:
pull_request:
types: [opened, synchronize]
# branches: [develop]
branches: [test]
branches: [develop]
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -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
7 changes: 3 additions & 4 deletions .github/workflows/deploy-dev-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

0 comments on commit 08402a6

Please sign in to comment.