amazon-s3gitlab-ciamazon-cloudfrontaws-cdk

Changed webpage files are not uploaded by aws CDK s3deploy.Source.asset


I have a aws s3 + cloudfront webpage deployed using CDK via gitlab pipeline. (code repo is here : https://github.com/ruwanindika/website)

Gitlab stages are "build" --> "deploy"

  1. In build stage I add a version number as below
script:
    - sed -i "s/%%VERSION%%/$CI_COMMIT_SHORT_SHA/" /builds/personal1741534/website/dist/index.html
  1. In deploy stage I execute below commands, but the changed index.html file is not uploaded to the s3 bucket and not showing up in the deployed webpage. Cloudfront cache is cleared automatically at deployment.
script:
    - cdk bootstrap
    - cdk deploy --require-approval never

CDK code for bucket deployment is below:

new BucketDeployment(this, "BucketDeployment", {
  destinationBucket: bucket,
  sources: [Source.asset("/builds/personal1741534/website/dist")],
  distribution,
  distributionPaths: ["/*"],
});

I expected the index.html file which was updated in build step of the gitlab pipeline will be deployed to the s3 and be visible in the webpage.


Solution

  • File changes in jobs are not persisted by default in GitLab. So changing a file in a job will not affect the files in any other job.

    To persist a job's output, use the artifacts key in the job:

    artifacts:
        - paths:
            - /builds/
    

    By default, all jobs in subsequent stages will download these artifacts.