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

add sample deployment guide #20

Merged
merged 3 commits into from
Jan 27, 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.ssh/
deploy/
# deploy/
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ listen to the port for TCP connections, but only if that port is available.
### How to use

```sh
ssh ssh.sdump.app
ssh -p 2222 ssh.sdump.app
```

### Commands

> If these commands don't work for you somehow, please let me know!

- `ctrl + y`: Copies the generated url you can use to debug
HTTP requests
- `ctrl + b`: Copies the JSON request body of the current request
Expand All @@ -43,3 +45,8 @@ you are viewing
### Developers' note

Use `ssh-keygen -f .ssh/id_rsa` to generate a test ssh key

### Deployment to your own server?

I have added a [guide](./deploy/README.md) here on how I have
deployed the public version
135 changes: 135 additions & 0 deletions deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Deployment

Here is a quick run through of how I have deployed the version that
you can test online today.

## HTTP server

I already have a K8s cluster I use to run my side projects and
[Ayinke Ventures](https://ayinke.ventures) so I have deployed
the http component there.

> K8s is overkill for this by the way. Just take the binary
and run it please

- `k8s/infisical.yml`: I use Infisical to manage all my secrets, I find
it easier to selfhost than Hashicorp Vault. This syncs all the
env value to the namespace and store in a secret called `managed_secret`

- `k8s/http-server.yml`: Creates a deployment and service

- `k8s/ingress.yml`: set ups Nginx ingress and tls termination
for the service created above

- `k8s/update_deployment.sh`: Takes an image ID and updates the image of the
deployment.
Eg: `./deploy/k8s/update_deployment.sh e84a5c5f3b8724072d48f8b96f7794fb`

## SSH server

I run the SSH command on a small ec2 instance I use for miscellaneous things.
I use `screen` to run this.

```sh

apt install -y screen
screen -dmS ssh_server ./sdump ssh

```

If you'd rather go fancy, you can use Systemd as described below or even
K8s 👿👿👿👿

### Systemd?

If you want to run this over systemd, this config should work ideally

```sh
sudo vi /etc/systemd/system/sdump.service
```

```text

[Unit]
Description=sdump
After=network.target

[Service]
Type=simple
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu/
ExecStart=server ssh
Restart=on-failure

[Install]
WantedBy=multi-user.target

```

```sh
sudo systemctl daemon-reload
sudo systemctl start sdump
```

I already use Caddy so all i needed to do was extend the config as below:

```json
{
"logging": {
"logs": {
"": {
"level": "debug"
}
}
},
"apps": {
"layer4": {
"servers": {
"sdump-ssh": {
"listen": [
"0.0.0.0:2222"
],
"routes": [
{
"match": [
{
"ssh": {}
}
],
"handle": [
{
"handler": "proxy",
"upstreams": [
{
"dial": [
"localhost:3333"
]
}
]
}
]
}
]
}
}
}
}
}
```

You need to build caddy to get L4 support to make the above config work.
Here is an example that should work:

```sh
xcaddy build \
--with github.com/mholt/caddy-l4/layer4 \
--with github.com/mholt/caddy-l4/modules/l4tls \
--with github.com/mholt/caddy-l4/modules/l4subroute \
--with github.com/mholt/caddy-l4/modules/l4http \
--with github.com/mholt/caddy-l4/modules/l4ssh \
--with github.com/mholt/caddy-l4/modules/l4proxy \
--with github.com/caddy-dns/duckdns
```

See [the documentation](https://github.com/mholt/caddy-l4) for more details
36 changes: 36 additions & 0 deletions deploy/k8s/http-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: v1
kind: Service
metadata:
name: sdump-api
namespace: sdump
spec:
ports:
- port: 80
targetPort: 4200
selector:
app: sdump-api
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: sdump-api
namespace: sdump
spec:
replicas: 1
selector:
matchLabels:
app: sdump-api
template:
metadata:
labels:
app: sdump-api
spec:
containers:
- name: server
image: ghcr.io/adelowo/sdump:e84a5c5f3b8724072d48f8b96f7794fb
imagePullPolicy: Always
envFrom:
- secretRef:
name: managed-secret
ports:
- containerPort: 4200
18 changes: 18 additions & 0 deletions deploy/k8s/infisical.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: secrets.infisical.com/v1alpha1
kind: InfisicalSecret
metadata:
name: infisicalsecret-sample
spec:
hostAPI: https://app.infisical.com/api
resyncInterval: 60
authentication:
serviceToken:
serviceTokenSecretReference:
secretName: service-token
secretNamespace: sdump
secretsScope:
envSlug: prod
secretsPath: "/"
managedSecretReference:
secretName: managed-secret
secretNamespace: sdump
27 changes: 27 additions & 0 deletions deploy/k8s/ingress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: sdump-api-ingress
namespace: sdump
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-production"
nginx.ingress.kubernetes.io/proxy-body-size: "10m"

spec:
tls:
- hosts:
- sdump.app
secretName: sdump-api-tls
rules:
- host: sdump.app
http:
paths:
- backend:
service:
name: sdump-api
port:
number: 80
pathType: Prefix
path: /

ingressClassName: nginx
13 changes: 13 additions & 0 deletions deploy/k8s/update_deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if [ -z "$1" ]; then
echo "Please provide the image version"
exit 10
fi

echo "Updating deployment to image with tag, $1"

kubectl set image deployment/sdump-api server=ghcr.io/adelowo/sdump:$1 --namespace sdump

echo "Checking rollout status... Hang on for around 5 seconds \n"
sleep .5

kubectl rollout status deployment.v1.apps/sdump-api --namespace sdump
Loading