Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically deploy contents to the development stage when changes are merged #4

Closed
2 tasks
kikuomax opened this issue Jun 13, 2022 · 21 comments · Fixed by #8
Closed
2 tasks

Automatically deploy contents to the development stage when changes are merged #4

kikuomax opened this issue Jun 13, 2022 · 21 comments · Fixed by #8
Assignees

Comments

@kikuomax
Copy link
Member

It would be nice if

  • contents are automatically deployed to the development stage when changes are merged,
  • the website is updated if the new contents are approved.
@kikuomax kikuomax self-assigned this Jun 13, 2022
@kikuomax
Copy link
Member Author

AWS CodePipeline comes in.

@kikuomax
Copy link
Member Author

kikuomax commented Jun 16, 2022

Pipeline steps,

  1. Merging a PR to the main branch triggers the pipeline.
  2. The build stage fetches source code and builds contents for development.
  3. The development-deploy stage copies the built contents to the contents bucket.
  4. The pipeline waits for my approval.
  5. I review the development website.
  6. I approve the contents.
  7. The release stage builds contents for production.
  8. The production-deploy stage copies the built contents to the contents bucket.

@kikuomax
Copy link
Member Author

I am going to initialize a separate CDK stack in a new cdk-ops folder.

@kikuomax
Copy link
Member Author

kikuomax commented Jun 16, 2022

How can I avoid duplicating DeploymentStage between cdk and cdk-ops?

@kikuomax
Copy link
Member Author

How can I avoid duplicating DeploymentStage between cdk and cdk-ops?

How about to use npm link --save?
https://docs.npmjs.com/cli/v8/commands/npm-link

@kikuomax
Copy link
Member Author

How can I avoid duplicating DeploymentStage between cdk and cdk-ops?

How about to use npm link --save? https://docs.npmjs.com/cli/v8/commands/npm-link

We have to be careful about the version of node modules installed in a linked package. If the host package and linked package share dependencies, their version must agree.

@kikuomax
Copy link
Member Author

I think I have hit this issue related to npm link.
npm/cli#2339

@kikuomax
Copy link
Member Author

kikuomax commented Jun 16, 2022

I do not have to stick to npm link, try npm install --install-links instead.

@kikuomax
Copy link
Member Author

I am still getting the following error,

npm ERR! src/deployment-stage.ts(1,22): error TS2307: Cannot find module 'constructs' or its corresponding type declarations.

No dependencies of the linked package are installed whether I use npm link or npm install --install-links.

@kikuomax
Copy link
Member Author

I think I have hit another serious bug.
npm/cli#4863

@kikuomax
Copy link
Member Author

I managed to circumvent the problem with npm link though, why not create a new stack in the cdk app?

@kikuomax
Copy link
Member Author

I managed to circumvent the problem with npm link though, why not create a new stack in the cdk app?

I wanted to loosely link the cdk and cdk-ops apps (stacks).

@kikuomax
Copy link
Member Author

I am going to connect the pipeline to this GitHub repository via CodeStartSourceConnection. And I have to learn about AWS CodeStar.

@kikuomax
Copy link
Member Author

Hmm.. I have to create an Amazon developer account to create a project with AWS CodeStar. Can I use only a GitHub connection that I have created during project creation without finishing the creation? Give it a shot anyway.

@kikuomax
Copy link
Member Author

I have to figure out how to run Zola with AWS CodeBuild.

@kikuomax
Copy link
Member Author

Zola provides a Docker image.

@kikuomax
Copy link
Member Author

Hmm.. I have to create an Amazon developer account to create a project with AWS CodeStar. Can I use only a GitHub connection that I have created during project creation without finishing the creation? Give it a shot anyway.

At least, I can list my GitHub connection with aws codestar-connections list-connections.

@kikuomax
Copy link
Member Author

Zola provides a Docker image.

I do not think I can rely on that image because sh is required by CodeBuild.
https://docs.aws.amazon.com/codebuild/latest/userguide/troubleshooting.html#troubleshooting-sh-build-images

@kikuomax
Copy link
Member Author

kikuomax commented Jun 17, 2022

How about to use Alpine Linux that is available at Amazon ECR Public Gallery.
https://gallery.ecr.aws/docker/library/alpine

I have confirmed that Zola can be easily installed on that image through the apk command.

@kikuomax
Copy link
Member Author

The operation CDK stack needs to know the following information,

  • the domain name of the CloudFront distribution for development
  • the name of the S3 bucket for development contents
  • the name of the S3 bucket for production contents

The above information can be obtained from the main CDK stacks because they output the above information.

@kikuomax
Copy link
Member Author

The above information can be obtained from the main CDK stacks because they output the above information.

We may tighten the link between the main CDK stacks and the operation CDK stack by exporting that information from the former to the latter. However, I had a bitter experience with exports in the past. It prohibited replacing the exported resources until the reference from the other stack was removed. So I am discouraged from exporting resources from a CloudFormation stack.

kikuomax added a commit to kikuomax/codemonger that referenced this issue Jun 19, 2022
- A new local package `cdk-common` that collects types and functions
  shared among CDK stacks in this repository is introduced. It provides
  the type `DeploymentStage` so far.
- A new CDK stack for continuous delivery is going to be introduced, and
  it will share some stuff like `DeploymentStage` with the CDK stack in
  the `cdk` folder.
- `cdk-common` is supposed to be locally linked from other projects with
  `npm link --save ../cdk-common`. There was an issue with the `prepare`
  life cycle script that no dependencies of `cdk-common` were installed
  before running the `prepare` script and the `prepare` script ended up
  with a build error. The `scripts/prepare.js` script circumvents this
  situation by invoking `npm install` if there is no `node_modules`
  folder in this project. See comments in `script/prepare.js` for more
  details.

issue codemonger-io#4
kikuomax added a commit to kikuomax/codemonger that referenced this issue Jun 19, 2022
- The `cdk-common` package is locally linked with
  `npm link --save ../cdk-common`.

issue codemonger-io#4
kikuomax added a commit to kikuomax/codemonger that referenced this issue Jun 19, 2022
- `DeploymentStage` and related functions are replaced with the ones
  defined in `cdk-common`.

issue codemonger-io#4
kikuomax added a commit to kikuomax/codemonger that referenced this issue Jun 19, 2022
- `README.md` briefly explains this library.

issue codemonger-io#4
kikuomax added a commit to kikuomax/codemonger that referenced this issue Jun 19, 2022
- `cdk-common` is linked.
- `aws-cdk` and `aws-cdk-lib` are bumped to 2.28.1.
- `constructs` is bumped to 10.1.42.

issue codemonger-io#4
kikuomax added a commit to kikuomax/codemonger that referenced this issue Jun 19, 2022
- The CDK stack is renamed to `codemonger-operation`.

issue codemonger-io#4
kikuomax added a commit to kikuomax/codemonger that referenced this issue Jun 19, 2022
- `@aws-sdk/client-cloudformation` is installed so that the CDK script
  can obtain outputs from the main stacks.

issue codemonger-io#4
kikuomax added a commit to kikuomax/codemonger that referenced this issue Jun 19, 2022
- A new CDK construct `ContentsPipeline` that provisions a CodePipeline
  pipeline that automates the workflow to update the contents of the
  codemonger website is introduced.
- A new CDK construct `CodemongerResources` that resolves resources in
  the main codemonger stacks is defined in a new file
  `lib/codemonger-resources.ts`. The file `lib/codemonger-resources.ts`
  also provides a function `resolveCodemongerResourceNames` that
  resolves the resource names in the main codemonger stacks by obtaining
  outputs from the stacks. `bin/cdk-ops.ts` invokes
  `resolveCodemongerResourceNames` and passes results to the constructor
  of `CdkOpsStack`.
- You have to prepare an untracked file (in `.gitignore`)
  `lib/github-connection-config.ts` that provides information to connect
  the pipeline and this GitHub repository.

issue codemonger-io#4
kikuomax added a commit to kikuomax/codemonger that referenced this issue Jun 19, 2022
- `README.md` and `README.ja.md` explain how to deploy this CDK stack.
  They also provide the following information,
    - About the workflow to be automated
    - Why exports of CloudFormation are not used

issue codemonger-io#4
kikuomax added a commit to kikuomax/codemonger that referenced this issue Jun 19, 2022
- `README.md` and `README.ja.md` explain what we have to do when we
  update the library.

issue codemonger-io#4
kikuomax added a commit to kikuomax/codemonger that referenced this issue Jun 19, 2022
- `README.md` and `README.ja.md` add a link to the subfolder `cdk-ops`.

issue codemonger-io#4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant