From 73fe95837816ae0e5d413803798d4cbf623eda7c Mon Sep 17 00:00:00 2001 From: Drew Bollinger Date: Tue, 25 Jun 2024 13:35:39 -0700 Subject: [PATCH] chore: add refactored pipeline --- ci/partials/build.yml | 6 + ci/partials/deploy.yml | 4 + ci/partials/install-dependencies.yml | 7 + ci/partials/test-redirects.yml | 15 ++ ci/pipeline.yml | 239 ++++++--------------------- ci/tasks/cancel-deployment.sh | 10 -- ci/tasks/restage.sh | 10 -- 7 files changed, 86 insertions(+), 205 deletions(-) create mode 100644 ci/partials/build.yml create mode 100644 ci/partials/deploy.yml create mode 100644 ci/partials/install-dependencies.yml create mode 100644 ci/partials/test-redirects.yml delete mode 100755 ci/tasks/cancel-deployment.sh delete mode 100755 ci/tasks/restage.sh diff --git a/ci/partials/build.yml b/ci/partials/build.yml new file mode 100644 index 0000000..b2a9805 --- /dev/null +++ b/ci/partials/build.yml @@ -0,0 +1,6 @@ +inputs: [name: src] +outputs: [name: src] +run: + dir: src + path: bash + args: [-c, npm run build] diff --git a/ci/partials/deploy.yml b/ci/partials/deploy.yml new file mode 100644 index 0000000..8a26082 --- /dev/null +++ b/ci/partials/deploy.yml @@ -0,0 +1,4 @@ +platform: linux +inputs: [name: src] +run: + path: src/ci/tasks/deploy.sh diff --git a/ci/partials/install-dependencies.yml b/ci/partials/install-dependencies.yml new file mode 100644 index 0000000..c296306 --- /dev/null +++ b/ci/partials/install-dependencies.yml @@ -0,0 +1,7 @@ +platform: linux +inputs: [name: src] +outputs: [name: src] +run: + dir: src + path: bash + args: [-c, npm install] diff --git a/ci/partials/test-redirects.yml b/ci/partials/test-redirects.yml new file mode 100644 index 0000000..f496984 --- /dev/null +++ b/ci/partials/test-redirects.yml @@ -0,0 +1,15 @@ +platform: linux +inputs: +- name: src +run: +dir: src +path: ci/docker/entrypoint.sh +args: + - bash + - -ceux + - | + docker network prune -f + docker-compose run test_client yarn test-integration + docker-compose stop + docker-compose down + docker network prune -f diff --git a/ci/pipeline.yml b/ci/pipeline.yml index 90b2a6b..ee8c951 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -1,88 +1,25 @@ -############################ -# SHARED +--- +#@ load("funcs.lib.yml", "slack_hook") +#@ load("@ytt:data", "data") +#@ load("@ytt:template", "template") -env-cf: &env-cf - CF_API: https://api.fr.cloud.gov - CF_USERNAME: ((redirects-cf-username)) - CF_PASSWORD: ((redirects-cf-password)) - CF_ORG: gsa-18f-federalist - CF_SPACE: redirects - CF_APP_NAME: pages-redirects - CF_STACK: cflinuxfs4 - -node-image: &node-image - platform: linux - image_resource: - type: registry-image - source: - aws_access_key_id: ((ecr-aws-key)) - aws_secret_access_key: ((ecr-aws-secret)) - repository: pages-node-v20 - aws_region: us-gov-west-1 - tag: latest - -cf-image: &cf-image - platform: linux - image_resource: - type: registry-image - source: - aws_access_key_id: ((ecr-aws-key)) - aws_secret_access_key: ((ecr-aws-secret)) - repository: general-task - aws_region: us-gov-west-1 - tag: latest +#! SHARED test-redirects: &test-redirects - task: install-dependencies - config: - <<: *node-image - inputs: [name: src] - outputs: [name: src] - run: - dir: src - path: bash - args: [-c, npm install] + image: node + file: src/ci/partials/install-dependencies.yml - task: build - config: - <<: *node-image - inputs: [name: src] - outputs: [name: src] - run: - dir: src - path: bash - args: [-c, npm run build] + image: node + file: src/ci/partials/build.yml - - in_parallel: - - task: test-redirects - privileged: true - config: - platform: linux - image_resource: - type: registry-image - source: - aws_access_key_id: ((ecr-aws-key)) - aws_secret_access_key: ((ecr-aws-secret)) - repository: pages-dind-v25 - aws_region: us-gov-west-1 - tag: latest - inputs: - - name: src - run: - dir: src - path: ci/docker/entrypoint.sh - args: - - bash - - -ceux - - | - docker network prune -f - docker-compose run test_client yarn test-integration - docker-compose stop - docker-compose down - docker network prune -f + - task: test-redirects + image: dind + privileged: true + file: src/ci/partials/test-redirects.yml -############################ -# JOBS +#! JOBS jobs: - name: test-redirects-pull-request @@ -99,6 +36,8 @@ jobs: status: pending base_context: concourse context: test-pull-request + - get: node + - get: dind - do: *test-redirects on_failure: @@ -110,14 +49,7 @@ jobs: status: failure base_context: concourse context: test-pull-request - - put: slack - params: - text: | - :x: FAILED: pages redirects tests on PR into main - <$ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME/"|View build details> - channel: ((slack-channel)) - username: ((slack-username)) - icon_url: ((slack-icon-url)) + - #@ slack_hook("failure", "tests") on_success: in_parallel: @@ -128,14 +60,7 @@ jobs: status: success base_context: concourse context: test-pull-request - - put: slack - params: - text: | - :white_check_mark: SUCCESS: Successfully tested pages redirects on PR into main - <$ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME/"|View build details> - channel: ((slack-channel)) - username: ((slack-username)) - icon_url: ((slack-icon-url)) + - #@ slack_hook("success", "tests") - name: test-and-deploy-redirects plan: @@ -143,49 +68,28 @@ jobs: resource: src trigger: true params: { depth: 1 } + - get: pipeline-tasks + - get: general-task + - get: node + - get: dind - do: *test-redirects - - task: deploy - config: - <<: *cf-image - inputs: [name: src] - run: - path: src/ci/tasks/deploy.sh + image: general-task + file: src/ci/partials/deploy.yml params: - <<: *env-cf + _: #@ template.replace(data.values.env_cf_redirects) CF_MANIFEST: src/out/manifest-prod.yml CF_PATH: src/out on_failure: try: task: cancel-api-deployment - config: - <<: *cf-image - inputs: [name: src] - run: - path: src/ci/tasks/cancel-deployment.sh + image: general-task + file: pipeline-tasks/tasks/cancel-deployment.yml params: - <<: *env-cf + _: #@ template.replace(data.values.env_cf_redirects) - on_failure: - in_parallel: - - put: slack - params: - text: | - :x: FAILED: deployment of pages redirects - <$ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME/"|View build details> - channel: ((slack-channel)) - username: ((slack-username)) - icon_url: ((slack-icon-url)) - on_success: - in_parallel: - - put: slack - params: - text: | - :white_check_mark: SUCCESS: Successfully deployed pages redirects - <$ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME/"|View build details> - channel: ((slack-channel)) - username: ((slack-username)) - icon_url: ((slack-icon-url)) + on_failure: #@ slack_hook("failure", "deployment") + on_success: #@ slack_hook("success", "deployment") - name: nightly-restage-redirects plan: @@ -194,26 +98,32 @@ jobs: params: { depth: 1 } - get: nightly trigger: true - - in_parallel: - - task: restage - config: - inputs: [name: src] - <<: *cf-image - run: - path: src/ci/tasks/restage.sh - params: - <<: *env-cf + - get: general-task + - get: pipeline-tasks + - task: restage + image: general-task + file: pipeline-tasks/tasks/restage.yml + params: + _: #@ template.replace(data.values.env_cf_redirects) - name: set-pipeline plan: - - get: pr + - get: src resource: pr trigger: true + - get: pipeline-tasks + - get: general-task + - task: init + image: general-task + file: pipeline-tasks/tasks/init.yml + params: + PIPELINE_YML: src/ci/pipeline.yml - set_pipeline: redirects - file: pr/ci/pipeline.yml + file: compiled/set-pipeline.yml + instance_vars: + deploy-env: ((deploy-env)) -############################ -# RESOURCES +#! RESOURCES resources: - name: pr @@ -242,57 +152,16 @@ resources: location: America/New_York - name: slack - type: slack-notification - source: - url: ((slack-webhook-url)) - + - name: node + - name: general-task + - name: dind + - name: pipeline-tasks -############################ -# RESOURCE TYPES +#! RESOURCE TYPES resource_types: - - name: git - type: registry-image - source: - aws_access_key_id: ((ecr_aws_key)) - aws_secret_access_key: ((ecr_aws_secret)) - repository: git-resource - aws_region: us-gov-west-1 - tag: latest - - name: slack-notification - type: registry-image - source: - aws_access_key_id: ((ecr_aws_key)) - aws_secret_access_key: ((ecr_aws_secret)) - repository: slack-notification-resource - aws_region: us-gov-west-1 - tag: latest - - name: pull-request - type: registry-image - source: - aws_access_key_id: ((ecr_aws_key)) - aws_secret_access_key: ((ecr_aws_secret)) - repository: github-pr-resource - aws_region: us-gov-west-1 - tag: latest - - name: time - type: registry-image - source: - aws_access_key_id: ((ecr_aws_key)) - aws_secret_access_key: ((ecr_aws_secret)) - repository: time-resource - aws_region: us-gov-west-1 - tag: latest - - name: registry-image - type: registry-image - source: - aws_access_key_id: ((ecr_aws_key)) - aws_secret_access_key: ((ecr_aws_secret)) - repository: registry-image-resource - aws_region: us-gov-west-1 - tag: latest diff --git a/ci/tasks/cancel-deployment.sh b/ci/tasks/cancel-deployment.sh deleted file mode 100755 index dddb26d..0000000 --- a/ci/tasks/cancel-deployment.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -set -e - -cf api $CF_API -cf auth - -cf t -o $CF_ORG -s $CF_SPACE - -cf cancel-deployment $CF_APP_NAME diff --git a/ci/tasks/restage.sh b/ci/tasks/restage.sh deleted file mode 100755 index 15166cb..0000000 --- a/ci/tasks/restage.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -set -e - -cf api $CF_API -cf auth - -cf t -o $CF_ORG -s $CF_SPACE - -cf restage $CF_APP_NAME --strategy rolling