Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

AWS Deployment

Arkadiusz Żmudzin edited this page Mar 10, 2020 · 33 revisions

This is a guide to deploy our vapor instance to AWS for making the CI/CD pipeline streamlined.

Steps

  1. Create AWS account
  2. Select free tier
  3. Sign into console

Create EC2 instance:

  1. Choose AMI:
  • Ubuntu Server 16.04 LTS (HVM), SSD Volume Type
  • Choose the 64-bit (x86) option
  1. Instance Type:
  • Choose the t2.micro Instance Type
  1. Configure Instance
  • Default settings
  1. Add Storage
  • Chance Size to: 20 GiB
  1. Add Tags
  • Default settings (no tags)
  1. Configure Security Groups
  • Add a rule: override the default ssh with "myIP/32"
  1. Review
  • Just launch the instance
  1. Tags Create a new key pair and name it "username-desktop"

  2. Add billing alerts

Instance setup

Update the server, install auto-upgrades and time service, reboot:

sudo su
apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get install htop -y
apt-get install unattended-upgrades -y && dpkg-reconfigure -plow unattended-upgrades
apt-get install ntp -y && ntpq -p && service ntp restart
reboot

sudo apt-get install clang libicu-dev libcurl4-openssl-dev lldb git wget unzip -y
sudo apt-get install swift vapor
echo "export PATH=/swift-4.2/usr/bin:\"\${PATH}\"" >> ~/.bashrc
source ~/.bashrc

follow medium until deploy.sh

  • clone olWebsite to ~/
  • run our custom deploy

new users need a key

Issue with port 80 on Ubuntu AWS

We had an issue that port 80 was not accessible from remote because of misconfiguration of iptables, even when you allow to access your server from every host on every port in EC2 Security Group setup.

To fix that, you need to call this command

sudo iptables -A IN_public_allow -p tcp -m tcp --dport 80 -m conntrack --ctstate NEW -j ACCEPT

Deploying new version

Building docker container

  1. Build new version image
sudo docker build -t oneleif-api:latest -f web.Dockerfile --build-arg env=production  . 
  1. Stop previous working version
sudo docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
c3788b91c762        oneleif-api         "/bin/sh -c './Run s…"   5 minutes ago       Up 5 minutes        0.0.0.0:80->80/tcp   oneleif-api
sudo docker stop oneleif-api
  1. Remove old container
sudo docker rm oneleif-api
  1. Create a new container and start it
sudo docker create -p 80:80 --name oneleif-api oneleif-api
sudo docker start oneleif-api

That's all :)

In order to see the logs of the running container execute this command:

sudo docker logs oneleif-api

Note: if you want to see the logs in real-time, add the -f option, then Ctrl+C to exit

References: