{"id":18573163,"url":"https://github.com/localstack-samples/sample-build-push-ecr","last_synced_at":"2025-04-10T07:31:54.705Z","repository":{"id":184486475,"uuid":"671240395","full_name":"localstack-samples/sample-build-push-ecr","owner":"localstack-samples","description":"Show how to deploy ECR, build docker images, push to ECR in multiple IaC frameworks. ","archived":true,"fork":false,"pushed_at":"2023-08-14T18:54:09.000Z","size":443,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-02-17T14:44:42.513Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/localstack-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-07-26T21:44:49.000Z","updated_at":"2024-07-10T12:12:07.000Z","dependencies_parsed_at":"2023-07-28T17:06:48.900Z","dependency_job_id":null,"html_url":"https://github.com/localstack-samples/sample-build-push-ecr","commit_stats":null,"previous_names":["localstack-samples/sample-build-push-ecr"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-build-push-ecr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-build-push-ecr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-build-push-ecr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fsample-build-push-ecr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/localstack-samples","download_url":"https://codeload.github.com/localstack-samples/sample-build-push-ecr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248176396,"owners_count":21060059,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T23:08:15.421Z","updated_at":"2025-04-10T07:31:54.345Z","avatar_url":"https://github.com/localstack-samples.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LocalStack ECR Project\n\nThis project uses mutliple IaC frameworks to deploy a Docker registry to AWS ECR, build a Docker image,\nand deploy the image to the ECR repo. Changes to files in the `./app` directory will cause the Docker\nimage to be rebuilt with the tag `latest` and redeployed.\n\n![\"Sample\"](./docs/img/solution-diags.png \"Sample\")\n\n# Setup\n\n### Assumptions\n\n- Latest DockerDesktop installed and running\n\n### Setup steps\n\n1. Install Node Version Manager (NVM)\n   https://github.com/nvm-sh/nvm#installing-and-updating\n2. Select Node version 18\n\n```shell\nnvm install 18\n```\n\n3. Install Terraform CDK\n\n```shell\nnpm install --global cdktf-cli@latest\n```\n\n4. Create a Python VENV (virtual env) and Install LocalStack CLI\n\n```shell\nmake setup-venv\n# make sure to use the venv by sourcing it\nsource venv/bin/activate\n```\n\n5. Start LocalStack\n\n```shell\n# Export your LocalStack license key\nexport LOCALSTACK_API_KEY=\u003cyour key\u003e\nmake start-localstack\n```\n\nThe above command will hang. You can shutdown LocalStack by running:\n\n```shell\nmake stop-localstack\n```\n\n# Terraform CDK IaC Instructions\n\nThis assumes your shells are using the NVM by running `nvm use node` and you have your python venv set by\nrunning `source venv/bin/activate`\n\n### Install pipeline packages\n\nYou need to do this initially, and if you manually add packages to `iac/terraform/cdk/package.json`\n\n```shell\nmake local-cdktf-install\n```\n\n### Deploy ECR Stack\n\n```shell\nmake local-cdktf-deploy\n```\n\n## Terraform CDK Poking Around\n\nLook in the `./app` directory to find the Dockerfile. You can modify it and re-run `make local-cdktf-deploy` and it will\nre-deploy.\n\nLook in the `./iac/terraform/cdk` directory to find the IaC project. Look at `main.ts` in there to see how the resources\nare created.\n\n### Dev Testing the Image\n\n#### Sample Workflow\n\nAssuming you've deployed everything above.\n\n1. Change the image. Modify the file `./app/Dockerfile`\n2. Run a container for our image\n\n```shell\ndocker run --rm localhost.localstack.cloud:4510/myrepo\n```\n\n3. Update the `./app/Dockerfile` again\n4. Re-deploy\n\n```shell \nmake local-cdktf-deploy\n```\n\n5. Run the container for our image again, see the difference you made to the image.\n\n```shell\ndocker run --rm localhost.localstack.cloud:4510/myrepo\n```\n\n6. Go back to step (3)\n\n# Pulumi IaC with Docker Provider Instructions\n\nIaC files located at `./iac/pulumi/ts-docker-provider/ecr`\n\n### Deploy with Pulumi IaC\n\n```shell\nunset AWS_PROFILE\n```\n\n```shell\nmake local-ecr-docker-deploy\n```\n\n### Pulumi Cleanup\n\nWhen you restart LocalStack, you want to cleanup the local Pulumi state.\n\n```shell\nmake local-pulumi-clean\n```\n\n# Pulumi Crosswalk IaC Instructions - Failing\n\nThere is an issue with the ECR deployment to LocalStack in this IaC pipeline right now.\nIaC files located at `./iac/pulumi/typescript/ecr`\n\n### Deploy with Pulumi IaC\n\n```shell\nunset AWS_PROFILE\n```\n\n```shell\nmake local-ecr-deploy\n```\n\n# AWS Deploy Instructions\n\nWe use the same IaC pipelines to deploy to AWS! This is a very important point that LocalStack enables teams\nto test their IaC pipelines locally before ever deploying them to a live AWS environment.\n\n## Set Live AWS Credentials\n\nHowever you set your credentials in your terminal, do it now.\n\n## Add Environment Config\n\nThis project stores Terraform state in an AWS S3 bucket in the target account.\nCreate an S3 bucket in your target account to hold the Terraform state\n\n```shell\naws s3 mb s3://\u003cname of your bucket\u003e-\u003cregion where bucket is\u003e --region \u003cregion where your bucket is\u003e\n# enable versioning in case of state corruption\naws s3api put-bucket-versioning --bucket \u003cyour full bucket name\u003e --versioning-configuration Status=Enabled\n```\n\nCreate a file called `nonenv.makefile` at the root of this project.\n\n```makefile\nnon%: export TERRAFORM_STATE_BUCKET=\u003cyour bucket name. ie my-happy-bucket-us-west-2\u003e\nnon%: export PULUMI_BACKEND_URL=s3://$(TERRAFORM_STATE_BUCKET)\n```\n\n## Deploy to AWS with Pulumi\n\n```shell\nmake non-ecr-docker-deploy\n```\n\n## Destroy the Deployed AWS Pulumi Stack\n\n```shell\nmake non-ecr-docker-destroy\n```\n\n## Deploy to AWS with Terraform-CDK\n\n```shell\nmake non-cdktf-deploy\n```\n\n## Destroy the Deployed Stack\n\n```shell\nmake non-cdktf-destroy\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalstack-samples%2Fsample-build-push-ecr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocalstack-samples%2Fsample-build-push-ecr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalstack-samples%2Fsample-build-push-ecr/lists"}