diff --git a/.woodpecker/cd.yml b/.woodpecker/cd.yml index a7f89e4..b386e9f 100644 --- a/.woodpecker/cd.yml +++ b/.woodpecker/cd.yml @@ -1,3 +1,4 @@ +--- # https://woodpecker-ci.org/docs/intro when: @@ -5,23 +6,28 @@ when: variables: - secrets: &secrets + images: + - &image_node node:18.16.0 + - &image_aws_cli amazon/aws-cli:2.15.50 + - &image_drone_cache meltwater/drone-cache:v1.4.0 + + deploy_secrets: &deploy_secrets - S3_BUCKET - CLOUDFRONT_DISTRIBUTION - AWS_ACCESS_KEY_ID - AWS_SECRET_ACCESS_KEY - AWS_REGION - cache: &cache_step - image: meltwater/drone-cache:v1.4.0 + cache_step: &cache_step + image: *image_drone_cache environment: AWS_ACCESS_KEY_ID: from_secret: CACHE_S3_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY: from_secret: CACHE_S3_SECRET_ACCESS_KEY - cache_settings: &cache_step_settings - cache_key: '{{ .Commit.Branch }}-{{ checksum "yarn.lock" }}' + cache_settings: &cache_settings + cache_key: '{{ .Commit.Branch }}/{{ checksum "yarn.lock" }}' archive_format: zstd bucket: from_secret: CACHE_S3_BUCKET @@ -34,46 +40,44 @@ variables: mount: - 'node_modules' - steps: + - name: cache/restore <<: *cache_step settings: - <<: *cache_step_settings + <<: *cache_settings restore: true - - - name: build/yarn - depends_on: [ cache/restore ] - image: node:18.16.0 + - name: build/nodejs + depends_on: [cache/restore] + image: *image_node commands: - - yarn install - - yarn build + - corepack enable yarn + - yarn install --prefer-offline + - yarn run build - name: cache/rebuild - depends_on: [ build/yarn ] + depends_on: [build/nodejs] <<: *cache_step settings: - <<: *cache_step_settings + <<: *cache_settings rebuild: true - - name: publish/s3 - depends_on: [ build/yarn ] + depends_on: [build/nodejs] when: - branch: main - image: amazon/aws-cli:2.15.50 + secrets: *deploy_secrets + image: *image_aws_cli commands: - - aws s3 sync --delete ./dist s3://$${S3_BUCKET}/ - secrets: - - <<: *secrets + - aws s3 sync --delete ./dist "s3://$${S3_BUCKET}/" - name: publish/cloudfront - depends_on: [ publish/s3 ] + depends_on: [publish/s3] when: - branch: main - image: amazon/aws-cli:2.15.50 + secrets: *deploy_secrets + image: *image_aws_cli commands: - - aws cloudfront create-invalidation --distribution-id $${CLOUDFRONT_DISTRIBUTION} --paths '/*' - secrets: - - <<: *secrets + - aws cloudfront create-invalidation --distribution-id + "$${CLOUDFRONT_DISTRIBUTION}" --paths '/*'