Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

caddy image #218

Merged
merged 6 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tfgrid3/staticwebsite/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt update && \
apt -y install wget curl vim net-tools iputils-ping openssh-server

RUN apt install -y debian-keyring debian-archive-keyring apt-transport-https curl && \
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg && \
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list && \
apt update && \
apt install caddy
RUN apt install -y git

RUN wget -O /sbin/zinit https://github.com/threefoldtech/zinit/releases/download/v0.2.5/zinit && \
chmod +x /sbin/zinit

RUN mkdir -p /etc/zinit
COPY zinit /etc/zinit
EXPOSE 9000

ENTRYPOINT [ "/sbin/zinit", "init" ]
50 changes: 50 additions & 0 deletions tfgrid3/staticwebsite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Static Website
get a static website up and running on a VM

## What is in this image
- Includes preinstalled wget, openssh-server, curl, git and caddy binaries.
- zinit process manager which is configured with these services:
- sshd: Starts OpenSSH server daemon
- sshkey: Adds the user SSH key to authorized_keys, so he can log in remotely to the host which running this image.
- clone: Clones the git repository to `website` directory.
- github_branch: Checkout out to a specific branch if `GITHUB_BRANCH` env var was provided.
- caddyfile: Constracts the Caddyfile.
- caddy: Runs the caddy server.

## Building

in the staticwebsite directory

`docker build -t {user|org}/staticwebsite .`

### Convert the docker image to Zero-OS flist
Easiest way to convert the docker image to Flist is using [Docker Hub Converter tool](https://hub.grid.tf/docker-convert), make sure you already built and pushed the docker image to docker hub before using this tool.


## Deploying
Easiest way to deploy a VM using the flist is to head to to our [dashboard](https://dashboard.grid.tf) and deploy a Virtual Machine by providing the flist URL.
* make sure to provide the correct entrypoint, and required env vars.
* another important perquisite is to have a disk mounted on `/var/lib/docker`. make sure its size is big enough to fit both the images for taiga, and the volumes which will store all the db and the media files, etc.

or use the dedicated Static Website application if available, which will deploy an instance that satisfies the above perquisites.



## Flist
### URL:
This Flist should be updated to official repo.
```
https://hub.grid.tf/mayarosamaa.3bot/mayarosama-staticwebsite-latest.flist
```

### Entrypoint
- `/sbin/zinit init`

### Required Env Vars
- `SSH_KEY`: User SSH public key.
- `GITHUB_URL`: Git Repository to be clonned.

### Optional Env Vars
- `GITHUB_BRANCH`: The git branch that is going to be served, if not provided the default branch will be served.
- `USER_DOMAIN`: The domain provided by the user.
- `HTML_DIR`: The directory inside the repository that has the static files to be served.
7 changes: 7 additions & 0 deletions tfgrid3/staticwebsite/zinit/caddy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exec: |
bash -c '
caddy run
'
after:
- caddyfile

15 changes: 15 additions & 0 deletions tfgrid3/staticwebsite/zinit/caddyfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exec: |
bash -c '

touch /Caddyfile
chmod 700 /Caddyfile
if [ ! -z "$USER_DOMAIN" ]; then
echo -e "$USER_DOMAIN { \n root * /$HTML_DIR \n file_server \n }" >> /Caddyfile
else
echo -e ":9000 { \n root * /$HTML_DIR \n file_server \n}" >> /Caddyfile
fi
'

after:
- github_branch
oneshot: true
2 changes: 2 additions & 0 deletions tfgrid3/staticwebsite/zinit/clone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exec: bash -c 'git clone $GITHUB_URL website'
hossnys marked this conversation as resolved.
Show resolved Hide resolved
oneshot: true
11 changes: 11 additions & 0 deletions tfgrid3/staticwebsite/zinit/github_branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exec: |
bash -c '
cd /website
if [ ! -z "$GITHUB_BRANCH" ]; then
git checkout $GITHUB_BRANCH -q
fi
'
after:
- clone

oneshot: true
1 change: 1 addition & 0 deletions tfgrid3/staticwebsite/zinit/sshd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exec: /usr/sbin/sshd -D
12 changes: 12 additions & 0 deletions tfgrid3/staticwebsite/zinit/sshkey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
exec: |
bash -c '
if [ ! -z "$SSH_KEY" ]; then
mkdir -p /var/run/sshd
mkdir -p /root/.ssh
touch /root/.ssh/authorized_keys

chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys
fi
'
oneshot: true