---
title: "Setup"
date: 
draft: true
---

# libertytools.io 

liberty tools is built using hugo, a static website generator. content is maintained in markdown files. hugo generates the website files using the chosen template and markdown files.

version control of the site content is maintained through git. when an update is pushed to the git repository on the server, a hook automatically runs hugo and rebuilds the website. 

## resources
[introduction to hugo](https://www.youtube.com/watch?v=qtIqKaDlqXo&list=PLLAZ4kZ9dFpOnyRlyS-liKL5ReHDcj4G3)

[introduction to git](https://www.youtube.com/watch?v=USjZcfj8yxE)

## server 

i used the following guides for initial setup of the server.

1. [initial setup](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-20-04)
2. [firewall](https://www.digitalocean.com/community/tutorials/how-to-setup-a-firewall-with-ufw-on-an-ubuntu-and-debian-cloud-server)
3. [SSH](https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-ubuntu-20-04)
4. [fail2ban](https://www.digitalocean.com/community/tutorials/how-to-protect-ssh-with-fail2ban-on-ubuntu-20-04)



i then setup docker containers for a basic reverse proxy, nginx web server, and lets encrypt using the following guide. 

5. [nginx reverse proxy with docker](https://linuxhandbook.com/nginx-reverse-proxy-docker/)

the exact file structure and docker compose files are below.

```
/opt/
...libertytools.io/
......docker-compose.yml
......nginx.conf
...reverse-proxy/
......docker-compose.yml
```

libertytoolsio/docker-compose.yml

```
version: "3.7"

services:

  libertytoolsio:

    image: nginx
    container_name: "libertytoolsio"
    restart: "always"
    volumes:
      - /hugo/libertytoolsio/public:/usr/share/nginx/html
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
    environment:
      VIRTUAL_HOST: "libertytools.io"
      VIRTUAL_PORT: 80
      LETSENCRYPT_HOST: "libertytools.io"
    networks: ["net"]

networks:
  net:
    external: true
```

libertytoolsio/nginx.conf

```
server {
  listen 80;
  location / {
    root /usr/share/nginx/html;
  }
}
```

reverse-proxy/docker-compose.yml

```
version: "3.7"

services:

    reverse-proxy:
        image: "jwilder/nginx-proxy:latest"
        container_name: "reverse-proxy"
        volumes:
            - "html:/usr/share/nginx/html"
            - "dhparam:/etc/nginx/dhparam"
            - "vhost:/etc/nginx/vhost.d"
            - "certs:/etc/nginx/certs"
            - "/run/docker.sock:/tmp/docker.sock:ro"
        restart: "always"
        networks:
            - "net"
        ports:
            - "80:80"
            - "443:443"

    letsencrypt:
        image: "jrcs/letsencrypt-nginx-proxy-companion:latest"
        container_name: "letsencrypt-helper"
        volumes:
            - "html:/usr/share/nginx/html"
            - "dhparam:/etc/nginx/dhparam"
            - "vhost:/etc/nginx/vhost.d"
            - "certs:/etc/nginx/certs"
            - "/run/docker.sock:/var/run/docker.sock:ro"
        environment:
            NGINX_PROXY_CONTAINER: "reverse-proxy"
            DEFAULT_EMAIL: "libertytools@pm.me"
        restart: "always"
        depends_on:
            - "reverse-proxy"
        networks:
            - "net"

volumes:
  certs:
  html:
  vhost:
  dhparam:

networks:
  net:
    external: true

```

## server side git

first i installed hugo. 

```sudo apt-get install hugo```

i then used the following guide for setting up git on the server. 

[deploy a website to remote server using git](https://hackernoon.com/deploy-website-to-remote-server-using-git-da6048805637)

the contents of the post-receive hook are below. 

```
#!/bin/sh
git --work-tree=/hugo/libertytoolsio --git-dir=/var/repo/libertytoolsio.git checkout -f
cd /hugo/libertytoolsio
hugo
```

this script is executed after a git push to the server. it copies everything to /hugo/libertytoolsio, moves to that directory, and runs hugo. running hugo regenerates the static website files from the markdown files.


## client side git

your ssh key must have been correctly copied to the authorized_keys file on the server before this will work, as described on the ssh guide linked above.

run the following command to copy the repository to your local device. note that here - courier is the user on the server, not your local user.

```
git clone courier@libertytools.io:/var/repo/libertytoolsio.git
```

then add the server as a remote repository. 

```
git remote add libertytoolsio ssh://courier@libertytools.io/var/repo/libertytoolsio.git/
```

## making changes

before working on updates, always pull the latest from the website. 

```
git pull libertytoolsio master
```

after making changes, commit them to the local repository. a commit message must always be included.

```
git add .
git commit -m 'message'
```

then push the changes to the server

`git push libertytoolsio`

## restoration

in the event of completely server destruction, the website can be easily rebuilt from this guide. since the core content of the site is backed up through git, it can be easily restored. 

the only difference should be to skip the git clone step locally, since there will be nothing to clone and the copy of the website already exists locally. you can simply git push to the server after creating a "bare" repo per the hackernoon guide. 

if any of the docker containers become corrupted, they can be safely deleted and rebuilt using the docker compose files. since deleting them won't destroy any key data. 



