How to deploy new code to ECS on EC2 using CodeDeploy?

0

We run ECS on EC2. Our containers are basically runtime and accessing website code through shared mount volume on EC2 instances. How do I use CodeDeploy ECS Blue/Green deployment to deploy new website code on shared mount volume on EC2 instances? I don't see a way to copy file to destination in ECS AppSpec.yml, not like EC2/on-premises AppSpec.yml that has "files" to do so. Should I use CodeDeploy EC2/on-premises? But that requires codedeploy-agent to be installed on EC2 instances which should not be for ECS.

asked 2 years ago556 views
3 Answers
0

Anti-pattern? If your site code is less than 5mb and doesn't have bunch of static images, videos and even audios, then that'd be fine to pack in your docker image.

answered 2 years ago
0

I should clarify it more clearly. Our code is packed in docker image, but not those static files including image, css, javascript, audio and video. We decide to move the bind mount from host volume to EFS. AWS Code Pipeline and Code Build allow us to deliver directly to EFS (NFS mount, basically) mounted on the instances. This way solves for us.

answered 2 years ago
-1

Accessing your code through a shared volume in your container is an anti-pattern. One of the benefits of containers is to package all your code, dependencies and runtime in the container. This will allow you to do blue/green deployments by having both versions of your app running in different set of containers and then switching traffic from the old version to the new one transparently for your users.

Mounting your code with a volume is fine to speed up development on your local workstation without rebuilding a full image on every code change, but for production deployment you should package everything in the container image.

profile pictureAWS
answered 2 years ago
  • FYI, maybe you are missing or anti-best practice. https://docs.docker.com/develop/dev-best-practices/ Instead, store data using volumes. https://developers.redhat.com/blog/2016/02/24/10-things-to-avoid-in-docker-containers

    1. Don't store data in containers - A container can be stopped, destroyed, or replaced. An application version 1.0 running in container should be easily replaced by the version 1.1 without any impact or loss of data. For that reason, if you need to store data, do it in a volume. In this case, you should also take care if two containers write data on the same volume as it could cause corruption. Make sure your applications are designed to write to a shared data store.
  • The original question was about "accessing website code through shared mount volume". Code is not data. This refers to anti-pattern 2 from the link. "2) Don't ship your application in two pieces". I agree that data like images and videos can be stored on a shared drive as this is content distinct from code.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions