Ship it!

Setting up EC2 instance

SSH into your instance and install docker and docker-compose on it. There are numerous tutorials available online on how to install them. So, I’m not gonna cover that here.

$ ssh-keygen -t rsa -b 4096 -f privkey

Setting up GitLab CI/CD job

I’m gonna show an opinionated GitLab CI configuration file, which we’ll be using to build and deploy the images from master branch of the repository.

GitLab CI Configuration.
  • DEPLOY_SERVER_IP : The IP address of the EC2 instance.
  • DEPLOY_HOST : The username of the EC2 instance, eg. ubuntu , if you use a ubuntu base image for setting up EC2 instance.
# .ci/deploy.sh#!/usr/bin/env bash
set -x -e -o pipefail
COMPOSE_LOCATION="/opt/<your_app_name>/master"
DOCKER_GROUP_NAME="docker"
# Early checks
which docker
which docker-compose
id -nG | grep "$DOCKER_GROUP_NAME"
# Start deployment
cd $COMPOSE_LOCATION
docker-compose pull
docker-compose up -d

--

--

A 23 y. o. Software Dev from India. Pythonista and JavaScript. Reach me at naveenkumarsangi@pm.me

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Naveen Kumar Sangi

Naveen Kumar Sangi

A 23 y. o. Software Dev from India. Pythonista and JavaScript. Reach me at naveenkumarsangi@pm.me