Needless to say, I am new to AWS. Excuse me.
I had a simple static site project (HTML/CSS/JS/PNG). Then put my files from root to /src
, and npm init
on root and amongst other things installed webpack dependency with which I can compile minimized and optimized files to the /dist
directory. npm run build
runs webpack
. This works perfectly.
Next I installed AWS Copilot CLI and initializes service which generated /copilot/{project-name}/manifest.yml
file:
name: {project-name}
type: Static Site
http:
redirect_to_https: true
path: '/'
alias: 'dev-{project-name}.{company}.{ltd}'
files:
- source: dist
recursive: true
environments:
stage:
http:
alias: 'staging-{project-name}.{company}.{ltd}'
prod:
http:
alias: '{project-name}.{company}.{ltd}'
Now I can manually build the dist folder with npm run build
and then use copilot svc deploy
and choose either of the three environments (development, stage, prod), and the generated files automatically show up in their respective S3 buckets, and all three websites work and have the SSL certificate. That is already amazing.
Next step, I would like to automate all three deploys on commit+push/merge to the main branch. I added /copilot/environments/{development/prod/stage}/manifest.yml
files, and they are correct. Then with copilot pipeline init
two more files were generated, /copilot/pipelines/{project-name}-main/{buildspec/manifest}.yml
. I’ve edited them a bit while playing around, but I cannot seem to get them to work properly. On code commit to BitBucket repo, AWS CodePipeline recognizes the change and starts the pipeline in stages Source -> Build -> DeployTo-development -> DeployTo-stage -> DeployTo-prod.
There are two problems.
- The pipeline does not respect the
requires_approval: true
limitation and all stages go through and are successfully completed. - Absolutely nothing updates in the S3 buckets.
I don’t know if something is wrong in my manifest/buildspec files or is there some hidden configuration in the AWS CodePipeline UI…
/copilot/pipelines/{project-name}-main/manifest.yml
name: {project-name}-main
version: 1
source:
provider: Bitbucket
properties:
branch: main
repository: https://bitbucket.org/{company-name}/{project-name}
# connection_name: a-connection
stages:
- name: development
# test_commands: [echo 'running tests', make test]
# deployments:
# {project-name}:
# template_path: infrastructure/development.env.yml
# template_config: infrastructure/development.env.params.json
# stack_name: {company-name}-development
- name: stage
requires_approval: true
# deployments:
# {project-name}:
# template_path: infrastructure/stage.env.yml
# template_config: infrastructure/stage.env.params.json
# stack_name: {company-name}-stage
- name: prod
requires_approval: true
# deployments:
# {project-name}:
# template_path: infrastructure/prod.env.yml
# template_config: infrastructure/prod.env.params.json
# stack_name: {company-name}-prod
/copilot/pipelines/{project-name}-main/buildspec.yml
version: 0.2
env:
variables:
NODE_ENV: development
DEBUG: false
# Note: This place is NOT meant for secrets (use parameter-store or secrets-manager instead)
# Note: Any env var defined here overrides existing ones (eg. Docker vars)
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
- mv ./copilot-linux-v1.33.4 ./copilot-linux
- chmod +x ./copilot-linux
- npm install
# pre_build:
# commands:
# - node --version # v20.11.1
# - npm --version # 10.2.4
# - aws --version # aws-cli/2.15.43 Python/3.11.8 Linux/4.14.291-218.527.amzn2.x86_64 exec-env/AWS_ECS_EC2 exe/x86_64.amzn.2023 prompt/off
# - ./copilot-linux --version # copilot version: v1.33.4
# - echo $CODEBUILD_SRC_DIR # /codebuild/output/src{some-numbers}/src
build:
commands:
- npm run build
- ls -lah ./dist
post_build:
commands:
- export COLOR="false"
- export CI="true"
- pipeline=$(cat $CODEBUILD_SRC_DIR/copilot/pipelines/{project-name}-main/manifest.yml | ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))')
- stages=$(echo $pipeline | jq -r '.stages[].name')
- >
for env in $stages; do
./copilot-linux env package -n $env --output-dir './infrastructure' --upload-assets --force;
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;
- echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>"
- echo $CODEBUILD_SRC_DIR
- ls -lah ./dist
- ls -lah ./infrastructure
artifacts:
files:
- "infrastructure/*"
In the “CodePipeline > Build” output I can see all files are in the /dist
folder, despite them not being in the repo, so npm run build
works correctly. Any help will be greatly appreciated.