Now that you have established an entrypoint script in your todobackend repository, you need to add this script to the existing Dockerfile and ensure the script is specified as the entrypoint using the ENTRYPOINT directive:
...
...
# Release stage
FROM alpine
LABEL=todobackend
# Install operating system dependencies
RUN apk add --no-cache python3 mariadb-client bash curl bats jq && \
pip3 --no-cache-dir install awscli
# Create app user
RUN addgroup -g 1000 app && \
adduser -u 1000 -G app -D app
# Copy and install application source and pre-built dependencies
COPY --from=test --chown=app:app /build /build
COPY --from=test --chown=app:app /app /app
RUN pip3 install -r /build/requirements.txt -f /build --no-index --no-cache-dir
RUN rm -rf /build
# Create public volume
RUN mkdir /public
RUN chown app:app /public
VOLUME /public
# Entrypoint script
COPY entrypoint.sh /usr/bin/entrypoint
RUN chmod +x /usr/bin/entrypoint
ENTRYPOINT ["/usr/bin/entrypoint"]
# Set working directory and application user
WORKDIR /app
USER app
In the preceding example, notice that you modify the first RUN directive to ensure the AWS CLI is installed, by adding the highlighted pip3 --no-cache install awscli command.
Finally, you copy the entrypoint script to /usr/bin/entrypoint, ensure the script has the executable flag set, and specify the script as the entrypoint for the image. Note that you must configure the ENTRYPOINT directive in the exec style format, to ensure the command that you run in your container is passed as arguments to the entrypoint script (see first note at https://docs.docker.com/engine/reference/builder/#cmd).
With your Dockerfile now updated, you need to commit your changes, rebuild and publish your Docker image changes as demonstrated in the following example:
> git add -A
> git commit -a -m "Add entrypoint script"
[master 5fdbe62] Add entrypoint script
4 files changed, 31 insertions(+), 7 deletions(-)
create mode 100644 entrypoint.sh
> export AWS_PROFILE=docker-in-aws
> make login
$(aws ecr get-login --no-include-email)
Login Succeeded
> make test && make release
docker-compose build --pull release
Building release
Step 1/28 : FROM alpine AS test
latest: Pulling from library/alpine
...
...
docker-compose run app bats acceptance.bats
Starting todobackend_db_1 ... done
Processing secrets []...
1..4
ok 1 todobackend root
ok 2 todo items returns empty list
ok 3 create todo item
ok 4 delete todo item
App running at http://localhost:32784
> make publish
docker-compose push release
Pushing release (385605022855.dkr.ecr.us-east-1.amazonaws.com/docker-in-aws/todobackend:latest)...
The push refers to repository [385605022855.dkr.ecr.us-east-1.amazonaws.com/docker-in-aws/todobackend]
fdc98d6948f6: Pushed
9f33f154b3fa: Pushed
d8aedb2407c9: Pushed
f778da37eed6: Pushed
05e5971d2995: Pushed
4932bb9f39a5: Pushed
fa63544c9f7e: Pushed
fd3b38ee8bd6: Pushed
cd7100a72410: Layer already exists
latest: digest: sha256:5d456c61dd23728ec79c281fe5a3c700370382812e75931b45f0f5dd1a8fc150 size: 2201
Pushing app (385605022855.dkr.ecr.us-east-1.amazonaws.com/docker-in-aws/todobackend:5fdbe62)...
The push refers to repository [385605022855.dkr.ecr.us-east-1.amazonaws.com/docker-in-aws/todobackend]
fdc98d6948f6: Layer already exists
9f33f154b3fa: Layer already exists
d8aedb2407c9: Layer already exists
f778da37eed6: Layer already exists
05e5971d2995: Layer already exists
4932bb9f39a5: Layer already exists
fa63544c9f7e: Layer already exists
fd3b38ee8bd6: Layer already exists
cd7100a72410: Layer already exists
34d86eb: digest: sha256:5d456c61dd23728ec79c281fe5a3c700370382812e75931b45f0f5dd1a8fc150 size: 2201
In the preceding example, when the Docker image is published, take note of the Docker tag for the app service (this is 5fdbe62 in my example, the actual hash will vary for you), which you recall from Chapter 1, specifies the Git commit hash of your source code repository. You will need this tag later on in this chapter to ensure you can deploy your changes to your todobackend application running in AWS.