Skip to content

Commit

Permalink
Merge pull request #89 from ContainerMaintainers/development
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
adamjhr authored Mar 25, 2023
2 parents b4dd6c8 + c2d6093 commit e6afa01
Show file tree
Hide file tree
Showing 14 changed files with 761 additions and 91 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/Continuous-Deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Minitwit Continuous Deployment

on:
push:
branches:
- main
workflow_run:
workflows:
- "Continuous Deployment"
types:
- completed
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build and push minitwitimage
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/minitwit:latest
cache-from: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/minitwit:webbuildcache
cache-to: type=registry,ref=${{ secrets.DOCKER_USERNAME }}/minitwit:webbuildcache,mode=max
build-args: |
db_name=${{ secrets.DB_NAME }}
db_port=${{ secrets.DB_PORT }}
db_password=${{ secrets.DB_PASSWORD }}
db_user=${{ secrets.DB_USER }}
db_host=${{ secrets.DB_HOST }}
session_key=${{ secrets.SESSION_KEY }}
port=${{ vars.PORT }}
gin_mode=${{ vars.GIN_MODE }}
- name: Deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script: bash deploy.sh containermaintainers ${{ vars.PORT }}
23 changes: 21 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,31 @@
FROM alpine:edge AS build
RUN apk add --no-cache --update go gcc g++

ARG db_user
ARG db_host
ARG db_password
ARG db_name
ARG db_port
ARG port
ARG session_key
ARG gin_mode

# Create a directory inside the container to store all our application
# and then make it the working directory.
WORKDIR /usr/src/app

# Copy everything and Download Go modules
# Copy everything
COPY . .

RUN sed -i 's/\r$//' env_file.sh

# Give permissions to run env_file.sh
RUN chmod +x env_file.sh

# Create .env if it doesn't exist
RUN sh env_file.sh ${db_user} ${db_password} ${db_name} ${db_port} ${db_host} ${port} ${session_key} ${gin_mode}

# Download Go modules
RUN go mod download && go mod tidy

# Build the application (this will build only minitwit.go)
Expand All @@ -19,4 +38,4 @@ EXPOSE 8080

# Now tell Docker what command to run when the container starts
# This will run the compiled minitwit file, when it is ready
CMD ["./minitwit"]
CMD ["./minitwit"]
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ Python has to be installed, as well as pytest (`pip install pytest`)
The tests are then run with `python -m pytest minitwit_sim_api_test.py`

To run the simulator: `python minitwit_simulator.py http://localhost:8080/sim`

## Monitoring with Grafana and Prometheus
Prometheus can be accessed at [http://localhost:9090](http://localhost:9090)
Grafana can be accessed at [http://localhost:3000](http://localhost:3000)
Metrics end point at [http://localhost:8080/metrics](http://localhost:8080/metrics)
62 changes: 38 additions & 24 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,42 +84,56 @@ Vagrant.configure("2") do |config|
end
end

server.vm.provision "shell", inline: 'echo "export DOCKER_USERNAME=' + "'" + ENV["DOCKER_USERNAME"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export DOCKER_PASSWORD=' + "'" + ENV["DOCKER_PASSWORD"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export DB_USER=' + "'" + ENV["DB_USER"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export DB_PASSWORD=' + "'" + ENV["DB_PASSWORD"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export DB_NAME=' + "'" + ENV["DB_NAME"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export DB_PORT=' + "'" + ENV["DB_PORT"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export PORT=' + "'" + ENV["PORT"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export SESSION_KEY=' + "'" + ENV["SESSION_KEY"] + "'" + '" >> ~/.bash_profile'
server.vm.provision "shell", inline: 'echo "export GIN_MODE=' + "'" + ENV["GIN_MODE"] + "'" + '" >> ~/.bash_profile'

server.vm.provision "shell", inline: <<-SHELL
export DB_IP=`cat /vagrant/db_ip.txt`
echo $DB_IP
echo "Installing go..."
sudo snap install go --classic
echo "Verifying go installation"
go version
echo "Installing docker..."
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
apt-cache policy docker-ce
sudo apt install -y docker-ce
sudo systemctl status docker
sudo usermod -aG docker ${USER}
echo "Installing gcc..."
sudo apt update
sudo apt -y install build-essential
echo "Verifying that docker works"
docker run --rm hello-world
docker rmi hello-world
echo "Verifying gcc installation"
gcc --version
echo "Adding environment variables to bash profile"
echo ". $HOME/.bashrc" >> $HOME/.bash_profile
echo $DB_IP
echo "Adding DB_HOST environment variable to bash profile"
echo "export DB_HOST='$DB_IP'" >> $HOME/.bash_profile
cp -r /vagrant/* $HOME
touch .env
echo "DB_HOST=$DB_IP" >> .env
echo "DB_PORT=5432" >> .env
echo "DB_USER=admin" >> .env
echo "DB_PASSWORD=admin" >> .env
echo "DB_NAME=minitwitdb" >> .env
echo "PORT=8080" >> .env
source $HOME/.bash_profile
echo "Assigning permission to run deploy.sh and env_file.sh"
chmod +x deploy.sh
chmod +x env_file.sh
echo "Building application"
docker build -t $DOCKER_USERNAME/minitwit:latest --build-arg db_user=$DB_USER --build-arg db_host=$DB_HOST --build-arg db_password=$DB_PASSWORD --build-arg db_name=$DB_NAME --build-arg db_port=$DB_PORT --build-arg port=$PORT --build-arg session_key=$SESSION_KEY --build-arg gin_mode=$GIN_MODE .
echo "Installing go modules"
go mod download
echo "Logging into docker"
docker login --username $DOCKER_USERNAME --pasword $DOCKER_PASSWORD
echo "Building Minitwit"
go build -o minitwit minitwit.go
echo "Running docker image..."
docker run --rm -d -p $PORT:$PORT --name minitwit $DOCKER_USERNAME/minitwit:latest
nohup ./minitwit > out.log &
echo "================================================================="
echo "= DONE ="
echo "================================================================="
Expand All @@ -131,4 +145,4 @@ Vagrant.configure("2") do |config|
config.vm.provision "shell", privileged: false, inline: <<-SHELL
sudo apt-get update
SHELL
end
end
Loading

0 comments on commit e6afa01

Please sign in to comment.