Reputation: 1851
I've leveraged several AWS services and I finally got the pipeline to work.
Using AWS Copilot CLI I inited to an existing application that already had the three (dev, stage, prod) environments, and I created my service and the (workloads) pipeline that triggers on commit to BitBucket.
As you can see in the last two stages of the pipeline, there is no manual approval step before actual deployment.
I know I can manually add these steps through the AWS CodePipeline's UI, but I was convinced the requires_approval: true
setting in the pipelines manifest would do the trick.
{project}/copilot/pipelines/{project}-main/manifest.yml
name: {project}-main
version: 1
source:
provider: Bitbucket
properties:
branch: main
repository: https://bitbucket.org/{company}/{project}
stages:
- name: development
- name: stage
requires_approval: true
- name: prod
requires_approval: true
{project}/copilot/pipelines/{pipeline}/buildspec.yml
version: 0.2
env:
variables:
NODE_ENV: development
DEBUG: false
phases:
install:
runtime-versions:
nodejs: 20.x
commands:
- cd $CODEBUILD_SRC_DIR
- wget -q https://ecs-cli-v2-release.s3.amazonaws.com/copilot-linux-v1.33.4 -O copilot-linux
- chmod +x ./copilot-linux
- npm install
build:
commands:
- npm run build
post_build:
commands:
- export COLOR="false"
- export CI="true"
- pipeline=$(cat $CODEBUILD_SRC_DIR/copilot/pipelines/{project}-main/manifest.yml | ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))')
- pl_envs=$(echo $pipeline | jq -r '.stages[].name')
- svc_ls_result=$(./copilot-linux svc ls --local --json)
- svc_list=$(echo $svc_ls_result | jq '.services')
- >
if [ ! "$svc_list" = null ]; then
svcs=$(echo $svc_ls_result | jq -r '.services[].name');
fi
- job_ls_result=$(./copilot-linux job ls --local --json)
- job_list=$(echo $job_ls_result | jq '.jobs')
- >
if [ ! "$job_list" = null ]; then
jobs=$(echo $job_ls_result | jq -r '.jobs[].name');
fi
- >
if [ "$svc_list" = null ] && [ "$job_list" = null ]; then
echo "No services or jobs found for the pipeline to deploy. Please create at least one service or job and push the manifest to the remote." 1>&2;
exit 1;
fi
- >
for env in $pl_envs; do
tag=$(echo ${CODEBUILD_BUILD_ID##*:}-$env | sed 's/:/-/g' | rev | cut -c 1-128 | rev)
for svc in $svcs; do
./copilot-linux svc package -n $svc -e $env --output-dir './infrastructure' --tag $tag --upload-assets;
if [ $? -ne 0 ]; then
echo "Cloudformation stack and config files were not generated. Please check build logs to see if there was a manifest validation error." 1>&2;
exit 1;
fi
done;
for job in $jobs; do
./copilot-linux job package -n $job -e $env --output-dir './infrastructure' --tag $tag --upload-assets;
if [ $? -ne 0 ]; then
echo "Cloudformation stack and config files were not generated. Please check build logs to see if there was a manifest validation error." 1>&2;
exit 1;
fi
done;
done;
artifacts:
files:
- "infrastructure/*"
{project}/copilot/{project}/manifest.yml
name: {project}
type: Static Site
http:
path: '/'
redirect_to_https: true
files:
- source: dist
environments:
development:
http:
alias: 'dev-{project}.{company}.rocks'
stage:
http:
alias: 'staging-{project}.{company}.rocks'
prod:
http:
alias: '{project}.{company}.rocks'
Am I missing something or is this not the option's intended usage?
Upvotes: 0
Views: 32