Consider the following Layerfile:
FROM vm/ubuntu:18.04
RUN apt-get update && \
apt-get install ca-certificates curl gnupg lsb-release && \
sudo mkdir -p /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" |\
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null && \
apt-get update && \
apt-get install docker-ce docker-ce-cli containerd.io python3 python3-pip awscli
RUN curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose
COPY . .
RUN REPEATABLE compose up -d --build --force-recreate --remove-orphans db redis
RUN docker-compose run web python3 manage.py migrate
SECRET ENV AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION
RUN aws s3 cp s3://staging_db_dumps/staging.sql /tmp/staging.sql
RUN cat /tmp/staging.sql | docker-compose exec -T db psql
There’s a lot to unpack here, but there are a few important takeaways from this
example:
- You can install docker & docker-compose and efficiently create containers
within a Layerfile
- RUN REPEATABLE lets you reuse built images & volumes from the last time this
pipeline ran
- Webapp.io will create a snapshot with everything created so that you can
avoid re-building, re-creating, and re-migrating database data every time.
As before, other Layerfiles can extend from this one to run e2e tests or create
a full-stack demo environment with EXPOSE WEBSITE
.