written 3.8 years ago by | • modified 3.4 years ago |
Setup a server to build docker images and push to ECR
For creating a Deployment Server, take a new / existing machine running Ubuntu 18.04.
And follow these steps:
- Install Docker
- Setup aws cli
- Change settings in your Django project to production
- Build docker image and push it to ECR
1. Install docker
2. Install and setup aws cli
3. Change settings in your Django project to production
Best practice is to create a separate settings file for production environment viz. prod.py
and extend your base settings.
from biostar.settings.base import *
# Replace settings and credentials below with the production ones
4. Build docker image and push to ECR
I've written a small deploy.sh script to build and push image to ECR.
#!/bin/bash
if [ $# -lt 2 ]
then
echo Please provide repository name and tag
exit 1
else
SOURCE_IMAGE=7813354292XX.dkr.ecr.us-east-1.amazonaws.com/$1:$2
echo ================ Building $SOURCE_IMAGE ==================
docker build -t "$SOURCE_IMAGE" .
echo ================ Pushing $SOURCE_IMAGE to ECR ================
eval $(aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 7813354292XX.dkr.ecr.us-east-1.amazonaws.com)
docker push $SOURCE_IMAGE
fi
It takes two parameters viz. repository name and image tag. The image will be built as per the Dockerfile
and will be pushed properly to aws cloud registry.
Building webserver image -
./deploy.sh q10_web prod.1.0
Also build deployment script for other images. Eg. I created a deployment script for nginx image and stored in it conf folder.
cd conf/docker/ngnix
./deploy.sh q10_nginx prod.1.0
Verify on ECR dashboard whether the images are built and pushed properly.