Now, we will move on to packaging the source code into a Docker image. But before packaging, we need to modify some configurations.
We have a bash script in the nodejs/scripts/start.sh
directory. As mentioned earlier, this script is responsible for setting up environment variables and starting the Node server using those variables.
First, reconnect to the EC2 instance via SSH in the production environment.
imga/backend
directory, which contains the backend source code for the project.vim nodejs/scripts/start.sh
to open this file in the VIM text editor.Inside this script, there are several environment variables like:
nvm
, node
, and npm
.Among these, AWS_REGION
(the region where the S3 Buckets are located) and BUCKET_NAME
(the name of the Bucket containing images) need to be updated accordingly. Once edited:
:wq
to save and exit.Following the push commands we reviewed earlier, the first step is to log in to Docker using credentials retrieved from ECR with the command aws ecr get-login-password
.
Once logged in, proceed to package the source code into a Docker image.
Check if the image has been built with the command docker image ls
. Finally, push the image to the repository created earlier.
Go to the repository to verify.
Now, the Docker image exists in our private repository. The next step will be to deploy the web server.