0.0.3 • Published 11 months ago

flight-hub-sqs v0.0.3

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
11 months ago

Template Node CI CD codeatifact

Summary

This workflow is used to upload your node artifact or dependency into the codeartifact repository.

NODE CODEARTIFACT CICD WORKFLOW

Usage pipeline

Call directly from your workflow file like:

jobs:
	NODE:
		uses: Iberia-Ent/software-engineering--workflow--node--ci--cd-codeartifact/.github/workflows/ci-cd-node-codeartifact.yml@v1.0
		secrets: inherit

Set up repository properties

Environment's configuration

You need to create the following environments in your repository:

  • Production: We recommend to insert a reviewers to approve the deployment in this environment until your team is sufficiently mature.

Variables configuration

On your repository, go to Settings > Secrets and Variables and add the following variables (repository scope):

  • CODEQL_LANGUAGES: This variable is used to set the languages to analyze with CodeQL. Example: javascript
  • RUNNER_GROUP: This variable is used to set your runner group. Example: my-group-runner
  • RUNNER_LABELS: This variable is used to set the runner labels. Example: "node", 'node', "label1","label2", 'label1','label2'
  • DEPLOY_GITHUB_PAGES: This variable is used to deploy your static code to github pages. Values: true | false

Secrets configuration

  • Create the secret AWS_RESOURCES_COMMON_ROLE (in secret section but repository scope) and add the value of the role of that account where you want to upload the artifacts.

Branches rules

  1. You will use the github flow, so you need to have the following branches:

    • main
    • features
    • feat/my-branch (working feature branch)
  2. Add some rules to main, develop and staging branch to make sure that you follow the flow and anyone can deploy in environments like preproduction or production.

    • main: - Require a pull request before merging and check "Require approvals" option. - Require status checks to pass before merging and check "Require branches to be up to date before merging" option. - Do not allow bypassing the above settings - Restrict who can push to matching branches: Add to the engineer, release management and technical lead product team.

    • features: - Require status checks to pass before merging and chech "Require branches to be up to date before merging" option and also add the status check of your pipeline for example: Initialize Environment, Continous Integration)

      		> [!NOTE]
      	  > For adding the status checks you should add them into pipeline code otherwise you couldn´t see it in rule branch section.
    • Do not allow bypassing the above settings - Restrict who can push to matching branches: Add to the engineer, release management and technical lead product team.

Setup pipeline

Pipeline files hierarchy

You will use the github flow for building and uploading the distribution package.

You should have these files:

  • .github/config/ci-config.json
  • .github/workflows/cd-codeartifact.yml
  • .github/workflows/dependabot.yml

You can modify these files:

  • .github/config/ci-config.json

Set up ci-config.json file

Variables

Find the variables that you need to set up in the ci-config.json file:

VariableRequiredType
AWS_RESOURCES_COMMON_ACCOUNT_IDyesstring
AWS_RESOURCES_COMMON_DOMAINyesstring
AWS_RESOURCES_COMMON_LIBRARY_REPOSITORY_FORMATyesstring
AWS_RESOURCES_COMMON_LIBRARY_REPOSITORY_NAMEyesstring
AWS_ECR_IMAGE_BASEyesstring
AWS_ECR_REGISTRYyesstring
AWS_ECR_REPOSITORY_NAMEyesstring
AWS_REGIONyesstring
NODE_VERSIONyesstring
S3_DEPLOY_BUCKET_REPOSITORY_NAMEyesstring
S3_PACKAGE_DISTRIBUTION_FORMATyesstring
S3_RELEASE_BUCKET_REPOSITORY_NAMEyesstring

For setting up the ci-config.json file with your custom properties of your project, go to your working feature branch and make the changes that you need using the above variables for example:

{
  "release": {
    "AWS_RESOURCES_COMMON_ACCOUNT_ID": "858599873024",
    "AWS_RESOURCES_COMMON_DOMAIN": "iberia",
    "AWS_RESOURCES_COMMON_LIBRARY_REPOSITORY_FORMAT": "npm",
    "AWS_RESOURCES_COMMON_LIBRARY_REPOSITORY_NAME": "npm-library-store",
    "AWS_ECR_IMAGE_BASE": "NA",
    "AWS_ECR_REGISTRY": "NA",
    "AWS_ECR_REPOSITORY_NAME": "NA",		
    "AWS_REGION": "eu-west-1",
    "NODE_VERSION": "18.x",
    "S3_DEPLOY_BUCKET_REPOSITORY_NAME": "NA",
    "S3_PACKAGE_DISTRIBUTION_FORMAT": "zip",
    "S3_RELEASE_BUCKET_REPOSITORY_NAME": "node-codeartifact-store-test"
  }
}

Upload your static content in github pages

If you want to deploy your static content in github pages, you should add the following code in your workflow file:

  • Make sure to have DEPLOY_GITHUB_PAGES variable in your repository.
  • Make sure to have S3_DEPLOY_BUCKET_REPOSITORY_NAME property in the ci-config.json file.
  • For building the static code, you need to have in the package.json the property: build:gh-pages
      "scripts": {
        ...
        "build:gh-pages": "storybook build",
        ...
      }
  • For uploading this distribution, the pipeline will take the code from storybook-static folder so make sure that your distribution is built in this folder.
  • Automatically, the pipeline will download your distribution folder and it will put it in the _site folder by default, folder where the github pages will take from there in order to deploy your static content.

Upload your artifact to the codeartifact repository

  • Create a working branch like feat/my-branch and insert and upload your code to the remote working branch.
  • Create a "Pull Request", select base branch: features and compare branch: feat/my-branch (working feature branch created for yourself).
  • Confirm your changes and the merge request.
  • Go to the "Action" tab and see if it has finished sucessfully or not and check the tag created automatically because you should create the release from that tag.
  • For uploading the artifact to the codeartifact repository, go to "tags" tab and create the release. Click in the "Generate release note" button and automatically will fill up the release. Add some detail in the tittle and description like:

    		Tittle: v1.0.0 - Added new code
    		Descrition: This is my first commit.
  • Go to "Actions" tab and see the status of the workflow, if it was sucessfully, your libraries are in production repository.

  • Create a "Pull Request" like: - Base branch: main - Compare branch: feat/my-branch (working feature branch).

  • Delete your custom branch. Example: feat/my-branch

Contributing

Briefly explains how your team members or others can contribute to the project

For the contribution and workflow guide, see CONTRIBUTING.md.

Maintainers

Contact information of the team member whose is responsible for the project, see CONTRIBUTING.md.