From 504c0e2704d2c3cb63c15a52319597bd0d7ba5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Fri, 1 May 2020 22:58:22 +0200 Subject: [PATCH 1/9] play: staging deployment --- .circleci/config.yml | 14 ++++++-------- scripts/transform.sh | 9 +++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 scripts/transform.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index d20c7526ed..144d8d21f7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,12 +10,7 @@ commands: description: Run Ditto in order to transform the base URL to https://pokeapi.co instead of localhost steps: - run: pip install --user -r requirements.txt - - run: - command: | - ~/.local/bin/ditto transform \ - --base-url='https://pokeapi.co' \ - --src-dir=data \ - --dest-dir=_gen + - run: bash scripts/transform.sh jobs: test: @@ -31,7 +26,8 @@ jobs: - run: tar czf _gen.tar.gz _gen/* - store_artifacts: path: _gen.tar.gz - - run: "curl -X POST --header \"Content-Type: application/json\" https://circleci.com/api/v1.1/project/github/PokeAPI/deploy/build?circle-token=$CIRCLECI_API_TOKEN" + # Trigger a new build of the deploy job of the deploy project + - run: curl --header "Content-Type: application/json" --data "{\"build_parameters\": {\"deploy_location\": \"$CIRCLE_BRANCH\", \"CIRCLE_JOB\": \"deploy\"}}" --request POST "https://circleci.com/api/v1.1/project/github/PokeAPI/deploy/tree/test-staging?circle-token=$CIRCLECI_API_TOKEN" workflows: version: 2 @@ -43,4 +39,6 @@ workflows: - test filters: branches: - only: master + only: + - master + - staging diff --git a/scripts/transform.sh b/scripts/transform.sh new file mode 100644 index 0000000000..fd13e895fc --- /dev/null +++ b/scripts/transform.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# Runs in CircleCI +# Replaces all the http://localhost links of api-data to match the corresponding deployment location. + +if [ "${CIRCLE_BRANCH}" = 'master' ]; then # https://stackoverflow.com/a/2013589/3482533 + ~/.local/bin/ditto transform --base-url='https://pokeapi.co' --src-dir=data --dest-dir=_gen +elif [ "${CIRCLE_BRANCH}" = 'test-staging' ]; then # Change to `staging` + ~/.local/bin/ditto transform --base-url='https://pokeapi-test-b6137.firebaseapp.com' --src-dir=data --dest-dir=_gen +fi From 20b5e6f5ab7ee562926b3ed5ab5d5de194987cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Fri, 1 May 2020 23:00:52 +0200 Subject: [PATCH 2/9] play: add quotes --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 144d8d21f7..91b5e1d4fe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,7 +27,7 @@ jobs: - store_artifacts: path: _gen.tar.gz # Trigger a new build of the deploy job of the deploy project - - run: curl --header "Content-Type: application/json" --data "{\"build_parameters\": {\"deploy_location\": \"$CIRCLE_BRANCH\", \"CIRCLE_JOB\": \"deploy\"}}" --request POST "https://circleci.com/api/v1.1/project/github/PokeAPI/deploy/tree/test-staging?circle-token=$CIRCLECI_API_TOKEN" + - run: 'curl --header "Content-Type: application/json" --data "{\"build_parameters\": {\"deploy_location\": \"$CIRCLE_BRANCH\", \"CIRCLE_JOB\": \"deploy\"}}" --request POST "https://circleci.com/api/v1.1/project/github/PokeAPI/deploy/tree/test-staging?circle-token=$CIRCLECI_API_TOKEN"' workflows: version: 2 From 1b219772910cd296203919ba04b0ff71d3e55744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Fri, 1 May 2020 23:09:25 +0200 Subject: [PATCH 3/9] refactor: change branch/debug --- .circleci/config.yml | 2 +- scripts/transform.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 91b5e1d4fe..8bf8fd5d37 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,7 +10,7 @@ commands: description: Run Ditto in order to transform the base URL to https://pokeapi.co instead of localhost steps: - run: pip install --user -r requirements.txt - - run: bash scripts/transform.sh + - run: bash -x scripts/transform.sh jobs: test: diff --git a/scripts/transform.sh b/scripts/transform.sh index fd13e895fc..e59387e6a9 100644 --- a/scripts/transform.sh +++ b/scripts/transform.sh @@ -4,6 +4,6 @@ if [ "${CIRCLE_BRANCH}" = 'master' ]; then # https://stackoverflow.com/a/2013589/3482533 ~/.local/bin/ditto transform --base-url='https://pokeapi.co' --src-dir=data --dest-dir=_gen -elif [ "${CIRCLE_BRANCH}" = 'test-staging' ]; then # Change to `staging` +elif [ "${CIRCLE_BRANCH}" = 'staging' ]; then ~/.local/bin/ditto transform --base-url='https://pokeapi-test-b6137.firebaseapp.com' --src-dir=data --dest-dir=_gen fi From cffc0fd6831d6fbc48e15ee5bd156caf49992a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Sat, 2 May 2020 15:54:16 +0200 Subject: [PATCH 4/9] docs: document steps --- .circleci/config.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8bf8fd5d37..345f8b6100 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,10 +7,14 @@ executors: commands: ditto-transform: - description: Run Ditto in order to transform the base URL to https://pokeapi.co instead of localhost + description: Run Ditto in order to transform the BASE_URL instead of http://localhost steps: - - run: pip install --user -r requirements.txt - - run: bash -x scripts/transform.sh + - run: + name: Install requirements.txt + command: pip install --user -r requirements.txt + - run: + name: Transform api-data's JSON files to have the correct BASE_URL instead of http://localhost + command: bash -x scripts/transform.sh jobs: test: @@ -23,11 +27,15 @@ jobs: steps: - checkout - ditto-transform - - run: tar czf _gen.tar.gz _gen/* + - run: + name: Pack the transofrmed data in a .tar.gz + command: tar czf _gen.tar.gz _gen/* - store_artifacts: path: _gen.tar.gz # Trigger a new build of the deploy job of the deploy project - - run: 'curl --header "Content-Type: application/json" --data "{\"build_parameters\": {\"deploy_location\": \"$CIRCLE_BRANCH\", \"CIRCLE_JOB\": \"deploy\"}}" --request POST "https://circleci.com/api/v1.1/project/github/PokeAPI/deploy/tree/test-staging?circle-token=$CIRCLECI_API_TOKEN"' + - run: + name: Trigger a deploy of the deploy project passing the desired environment/location to deploy to + command: 'curl --header "Content-Type: application/json" --data "{\"build_parameters\": {\"deploy_location\": \"$CIRCLE_BRANCH\", \"CIRCLE_JOB\": \"deploy\"}}" --request POST "https://circleci.com/api/v1.1/project/github/PokeAPI/deploy/tree/test-staging?circle-token=$CIRCLECI_API_TOKEN"' workflows: version: 2 From aec54bd9c024d75525417524c287ee9168c76eab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Sat, 2 May 2020 16:02:03 +0200 Subject: [PATCH 5/9] fix: typo --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 345f8b6100..ec6b912630 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,7 +28,7 @@ jobs: - checkout - ditto-transform - run: - name: Pack the transofrmed data in a .tar.gz + name: Pack the transformed data in a .tar.gz command: tar czf _gen.tar.gz _gen/* - store_artifacts: path: _gen.tar.gz From 8d89c05da846b9e005f1c0eeefc570b87209a2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Sat, 2 May 2020 20:56:40 +0200 Subject: [PATCH 6/9] play: checkout staging so to have all new commits --- updater/cmd.bash | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/updater/cmd.bash b/updater/cmd.bash index 4b3129b4a4..40590d73c7 100644 --- a/updater/cmd.bash +++ b/updater/cmd.bash @@ -16,7 +16,7 @@ export COMPOSE_INTERACTIVE_NO_CLI=1 dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2375 &> /dev/null & git clone --depth=1 "$REPO_POKEAPI" pokeapi -git clone --depth=1 "$REPO_DATA" api-data +git clone "$REPO_DATA" api-data # set up the pokeapi side cd pokeapi @@ -30,8 +30,9 @@ docker-compose exec -T app sh -c 'echo "from data.v2.build import build_all; bui # set up the data side cd ../api-data -git branch -D "$BRANCH_NAME" || true -git branch "$BRANCH_NAME" +# git branch -D "$BRANCH_NAME" || true +# git branch "$BRANCH_NAME" +# git checkout "$BRANCH_NAME" git checkout "$BRANCH_NAME" pip install -r requirements.txt From 69c1e2babef3fc452a3c04941a7da71688438907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Sat, 2 May 2020 21:09:13 +0200 Subject: [PATCH 7/9] play: add comments --- updater/cmd.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/updater/cmd.bash b/updater/cmd.bash index 40590d73c7..05dbdacad9 100644 --- a/updater/cmd.bash +++ b/updater/cmd.bash @@ -30,10 +30,10 @@ docker-compose exec -T app sh -c 'echo "from data.v2.build import build_all; bui # set up the data side cd ../api-data -# git branch -D "$BRANCH_NAME" || true +# git branch -D "$BRANCH_NAME" || true # TODO: uncomment # git branch "$BRANCH_NAME" # git checkout "$BRANCH_NAME" -git checkout "$BRANCH_NAME" +git checkout "$BRANCH_NAME" # TODO: remove pip install -r requirements.txt rm -r ./data From 381ac1c35c04eb23dd38ee4ad6ac07986e8b0e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Sun, 3 May 2020 00:12:28 +0200 Subject: [PATCH 8/9] chore: add TODO comment --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ec6b912630..93dc3da4e7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -35,7 +35,7 @@ jobs: # Trigger a new build of the deploy job of the deploy project - run: name: Trigger a deploy of the deploy project passing the desired environment/location to deploy to - command: 'curl --header "Content-Type: application/json" --data "{\"build_parameters\": {\"deploy_location\": \"$CIRCLE_BRANCH\", \"CIRCLE_JOB\": \"deploy\"}}" --request POST "https://circleci.com/api/v1.1/project/github/PokeAPI/deploy/tree/test-staging?circle-token=$CIRCLECI_API_TOKEN"' + command: 'curl --header "Content-Type: application/json" --data "{\"build_parameters\": {\"deploy_location\": \"$CIRCLE_BRANCH\", \"CIRCLE_JOB\": \"deploy\"}}" --request POST "https://circleci.com/api/v1.1/project/github/PokeAPI/deploy/tree/test-staging?circle-token=$CIRCLECI_API_TOKEN"' # # TODO: replace `test-staging` with `master` workflows: version: 2 From 7a28bfb14a258ea222359c0f73efb1a24e69ba73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Pezz=C3=A8?= Date: Wed, 13 May 2020 13:34:25 +0200 Subject: [PATCH 9/9] refactor: use deploy's master/address comments --- .circleci/config.yml | 2 +- updater/cmd.bash | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 93dc3da4e7..b4eacac4a9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -35,7 +35,7 @@ jobs: # Trigger a new build of the deploy job of the deploy project - run: name: Trigger a deploy of the deploy project passing the desired environment/location to deploy to - command: 'curl --header "Content-Type: application/json" --data "{\"build_parameters\": {\"deploy_location\": \"$CIRCLE_BRANCH\", \"CIRCLE_JOB\": \"deploy\"}}" --request POST "https://circleci.com/api/v1.1/project/github/PokeAPI/deploy/tree/test-staging?circle-token=$CIRCLECI_API_TOKEN"' # # TODO: replace `test-staging` with `master` + command: 'curl --header "Content-Type: application/json" --data "{\"build_parameters\": {\"deploy_location\": \"$CIRCLE_BRANCH\", \"CIRCLE_JOB\": \"deploy\"}}" --request POST "https://circleci.com/api/v1.1/project/github/PokeAPI/deploy/tree/master?circle-token=$CIRCLECI_API_TOKEN"' workflows: version: 2 diff --git a/updater/cmd.bash b/updater/cmd.bash index 05dbdacad9..4b3129b4a4 100644 --- a/updater/cmd.bash +++ b/updater/cmd.bash @@ -16,7 +16,7 @@ export COMPOSE_INTERACTIVE_NO_CLI=1 dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2375 &> /dev/null & git clone --depth=1 "$REPO_POKEAPI" pokeapi -git clone "$REPO_DATA" api-data +git clone --depth=1 "$REPO_DATA" api-data # set up the pokeapi side cd pokeapi @@ -30,10 +30,9 @@ docker-compose exec -T app sh -c 'echo "from data.v2.build import build_all; bui # set up the data side cd ../api-data -# git branch -D "$BRANCH_NAME" || true # TODO: uncomment -# git branch "$BRANCH_NAME" -# git checkout "$BRANCH_NAME" -git checkout "$BRANCH_NAME" # TODO: remove +git branch -D "$BRANCH_NAME" || true +git branch "$BRANCH_NAME" +git checkout "$BRANCH_NAME" pip install -r requirements.txt rm -r ./data