Skip to content

chunkhang/justcolor.io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

justcolor.io

Just the color, and nothing else

Just Color is a useless website to quickly display a certain color. Who needs those fancy color tools like ColorHexa? Sometimes, you just need the color, and nothing else.

Dependencies

Installation

Run just bootstrap to:

  • Verify that all system dependencies are present
  • Install project dependencies

Development

Running

Run just start to start the development server. Hot reload is handled by Flask. The application can be accessed via localhost:5000.

Stopping

Stop the development server any time with the usual Ctrl-C.

Production

Running

Run just up to start the production server. Gunicorn will be run by Supervisor, which itself runs as a daemon. The application can be accessed via localhost:5000.

Checking

Run just status to check the status of the production server.

Restarting

Run just restart to restart the production server if there are new changes to the application code.

Stopping

Run just down to stop the production server.

Deployment

Instance

For now, it is assumed that the deployment is done on an EC2 instance running Amazon Linux 2. Install all system dependencies listed above.

SSH

Configure the SSH alias justcolor.io in ~/.ssh/config:

Host justcolor.io
  HostName <elastic ip address>
  IdentityFile <pem file>
  User ec2-user

Now, we can SSH into the remote instance with:

ssh justcolor.io

Git

Remotely, set up two directories for Git: bare and working.

ssh justcolor.io
mkdir -p repo/justcolor.io.git repo/justcolor.io
cd repo/justcolor.io.git
git init --bare

For the bare repository justcolor.io.git, the hooks/post-update executable file should look something like this:

#!/bin/bash

git --work-tree ~/repo/justcolor.io --git-dir ~/repo/justcolor.io.git checkout --force
cd ~/repo/justcolor.io
just bootstrap
just restart

Locally, the Git remote live should point to the EC2 instance via SSH.

git remote add live ssh://justcolor.io/home/ec2-user/repo/justcolor.io.git

Basically, when we push to live remote, the post-update hook will update the working directory justcolor.io with the latest code from master branch. After that, the project is bootstrapped before the production server is restarted.

NGINX

Install and set up NGINX to proxy public requests to the production server. Assuming Let's Encrypt was set up using Certbot, the /etc/nginx/nginx.conf file should look something like this:

worker_processes 1;

events {
  worker_connections 1024;
}

http {
  include       mime.types;
  default_type  application/octet-stream;

  sendfile  on;
  gzip      on;

  keepalive_timeout  5;

  server {
    listen 80;

    server_name justcolor.io;

    location / {
      return 301 https://$server_name$request_uri;
    }
  }

  server {
    listen 443 ssl;

    server_name justcolor.io;

    ssl_certificate      /etc/letsencrypt/live/justcolor.io/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/justcolor.io/privkey.pem;

    location / {
      proxy_pass         http://127.0.0.1:5000/;
      proxy_redirect     off;

      proxy_set_header   Host                 $host;
      proxy_set_header   X-Real-IP            $remote_addr;
      proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
      proxy_set_header   X-Forwarded-Proto    $scheme;
    }
  }
}

Deploying

For the first deployment, manually start the production server and NGINX:

ssh justcolor.io
cd repo/justcolor.io
just up
sudo nginx

For subsequent deployments, run just deploy to deploy new changes to the live server.

About

Just the color, and nothing else

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors