Skip to content

Commit

Permalink
attempt web deployment system
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvicenti committed Aug 13, 2024
1 parent 1809963 commit c6c172b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 48 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ either deploy a site on a production server or run it locally in dev mode

To deploy a group into a site, make sure you have a domain name and
a server with the following requirements:

1. At least 2GB RAM
2. Al least 512MB free space in root partition.
2. Al least 512MB free space in root partition.
3. Port 56000 open so the p2p connections can reach the server.

After checking that, run the following command in the server:
Expand All @@ -84,7 +85,7 @@ replacing `https://example.com` by your <`address`> If everything went well,
after some seconds, you should be watching a final output line like
`https://example.com/secret-invite/XXXX`. You should paste that link back into
the owner's application to register the newly created site and start publihing.
The site deployment workspace will default to `~/.mtt-site`.
The site deployment workspace will default to `~/.seed-site`.

#### Auto-Update a Site

Expand All @@ -98,16 +99,17 @@ sh <(curl -sL https://go.hyper.media/website_deployment.sh) https://example.com
#### Replace Site

If you want to replace an old site with a new site in a different domain in the same machine,
you need to redeploy the site from scratch. Note that old content will be available as long as
you need to redeploy the site from scratch. Note that old content will be available as long as
the owner of the site is synced with the site at the moment of the replacement. On the server:

```shell
docker stop seedsite
mv ~/.mtt-site ~/.mtt-site.bak
mv ~/.seed-site ~/.seed-site.bak
docker start seedsite
```

Get the new secret link from the command line after starting the `seedsite` container
Now in the Seed App, the Owner of the site can go to the group he/she wants to (re)deploy
Now in the Seed App, the Owner of the site can go to the group he/she wants to (re)deploy
and click on the three dots, and publish group to site. Enter the new secret and the old content
should be now available in the new site. If there is no new content (A completely new group), then
should be now available in the new site. If there is no new content (A completely new group), then
the site will be empty ready to accept documents
2 changes: 1 addition & 1 deletion backend/cmd/seed-site/sites/config.go.off
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "seed/backend/config"
// DefaultConfig for sites.
func DefaultConfig() config.Config {
cfg := config.Default()
cfg.DataDir = "~/.mtt-site"
cfg.DataDir = "~/.seed-site"
cfg.Syncing.NoPull = true
cfg.Syncing.NoDiscovery = true
cfg.P2P.ForceReachabilityPublic = true
Expand Down
60 changes: 30 additions & 30 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ networks:
driver: bridge # the default
services:
proxy:
container_name: ${MTT_SITE_PROXY_CONTAINER_NAME:-PROXY}
container_name: ${SEED_SITE_PROXY_CONTAINER_NAME:-PROXY}
image: caddy:2.6.4
depends_on:
- seed-site
- seed-daemon
- web
ports:
- "80:80"
- "443:443"
Expand All @@ -16,51 +17,50 @@ services:
networks:
- internal_network
environment:
- "MTT_SITE_HOSTNAME=${MTT_SITE_HOSTNAME:-http://remix}"
- "MTT_SITE_BACKEND_GRPCWEB_PORT=${MTT_SITE_BACKEND_GRPCWEB_PORT:-56001}"
- "MTT_SITE_LOCAL_PORT=${MTT_SITE_LOCAL_PORT:-3000}"
- "SEED_SITE_HOSTNAME=${SEED_SITE_HOSTNAME}"
- "SEED_SITE_BACKEND_GRPCWEB_PORT=${SEED_SITE_BACKEND_GRPCWEB_PORT:-56001}"
- "SEED_SITE_LOCAL_PORT=${SEED_SITE_LOCAL_PORT:-3000}"
volumes:
- ${MTT_SITE_WORKSPACE:-~/.seed-site}/proxy/data:/data
- ${MTT_SITE_WORKSPACE:-~/.seed-site}/proxy/config:/config
- ${MTT_SITE_WORKSPACE:-~/.seed-site}/proxy/CaddyFile:/etc/caddy/Caddyfile
- ${SEED_SITE_WORKSPACE:-~/.seed-site}/proxy/data:/data
- ${SEED_SITE_WORKSPACE:-~/.seed-site}/proxy/config:/config
- ${SEED_SITE_WORKSPACE:-~/.seed-site}/proxy/CaddyFile:/etc/caddy/Caddyfile

web:
container_name: ${MTT_SITE_REMIX_CONTAINER_NAME:-web}
image: seedhypermedia/web:${MTT_SITE_TAG:-latest}
seed-web:
container_name: seed-web
image: seedhypermedia/gateway:${SEED_SITE_TAG:-latest}
depends_on:
- seed-daemon
networks:
- internal_network
ports:
- "${MTT_SITE_LOCAL_PORT:-3000}:${MTT_SITE_LOCAL_PORT:-3000}"
- "${SEED_SITE_LOCAL_PORT:-3000}:${SEED_SITE_LOCAL_PORT:-3000}"
restart: unless-stopped
volumes:
- ${MTT_SITE_WORKSPACE:-~/.seed-site}/web:/data:rw
- ${SEED_SITE_WORKSPACE:-~/.seed-site}/web:/data:rw
environment:
- "SEED_BASE_URL=${MTT_SITE_HOSTNAME:-http://web}"
- "GRPC_HOST=http://seed-site:${MTT_SITE_BACKEND_GRPCWEB_PORT:-56001}"
- "NEXT_PUBLIC_LN_HOST=${MTT_SITE_LN_HOST:-https://ln.mintter.com}"
- "SEED_BASE_URL=${SEED_SITE_HOSTNAME}"
- "GRPC_HOST=http://seed-site:${SEED_SITE_BACKEND_GRPCWEB_PORT:-56001}"
- "DATA_DIR=/data"

seed-site:
image: seedhypermedia/site:${MTT_SITE_TAG:-latest}
seed-daemon:
container_name: seed-daemon
image: seedhypermedia/site:${SEED_SITE_TAG:-latest}
restart: unless-stopped
container_name: ${SEED_SITE_DAEMON_CONTAINER_NAME:-seed-site}
ports:
- "56000:56000"
- "56000:56000/udp"
networks:
- internal_network
environment:
- "SENTRY_DSN=${MTT_SITE_SENTRY_DSN:-https://47c66bd7a6d64db68a59c03f2337e475@o4504088793841664.ingest.sentry.io/4505527493328896}"
- "SENTRY_DSN=${SEED_SITE_SENTRY_DSN:-https://47c66bd7a6d64db68a59c03f2337e475@o4504088793841664.ingest.sentry.io/4505527493328896}"
volumes:
- ${MTT_SITE_WORKSPACE:-~/.seed-site}/backend:/.seed-site:rw
- ${MTT_SITE_MONITORING_WORKDIR:-./monitoring}/grafana:/exported_grafana:rw
- ${MTT_SITE_MONITORING_WORKDIR:-./monitoring}/prometheus:/exported_prometheus:rw
- ${SEED_SITE_WORKSPACE:-~/.seed-site}/daemon:/data:rw
- ${SEED_SITE_MONITORING_WORKDIR:-./monitoring}/grafana:/exported_grafana:rw
- ${SEED_SITE_MONITORING_WORKDIR:-./monitoring}/prometheus:/exported_prometheus:rw
command: >
sh -c "rsync -a /monitoring/prometheus/ /exported_prometheus &&
rsync -a /monitoring/grafana/ /exported_grafana &&
seed-site -data-dir=/.seed-site -lndhub.mainnet -p2p.port=56000 --http.port=${SEED_SITE_BACKEND_GRPCWEB_PORT:-56001} -syncing.allow-push=${SEED_SITE_ALLOW_PUSH:-false} -grpc.port=56002 -syncing.no-discovery=${SEED_SITE_NO_DISCOVERY:-true} -syncing.no-pull=${SEED_SITE_NO_PULL:-true} ${SEED_SITE_HOSTNAME:-http://remix}"
seed-daemon -data-dir=/data -lndhub.mainnet -p2p.port=56000 --http.port=${SEED_SITE_BACKEND_GRPCWEB_PORT:-56001} -syncing.allow-push=${SEED_SITE_ALLOW_PUSH:-false} -grpc.port=56002 -syncing.no-discovery=${SEED_SITE_NO_DISCOVERY:-true} -syncing.no-pull=${SEED_SITE_NO_PULL:-true} ${SEED_SITE_HOSTNAME}"
prometheus:
image: prom/prometheus:latest
Expand All @@ -76,7 +76,7 @@ services:
- "host.docker.internal:host-gateway"
volumes:
- prometheus-data:/prometheus
- ${MTT_SITE_MONITORING_WORKDIR:-./monitoring}/prometheus/prometheus.yaml:/etc/prometheus/prometheus.yml:ro
- ${SEED_SITE_MONITORING_WORKDIR:-./monitoring}/prometheus/prometheus.yaml:/etc/prometheus/prometheus.yml:ro

grafana:
image: grafana/grafana:main
Expand All @@ -90,15 +90,15 @@ services:
- internal_network
volumes:
- grafana-data:/var/lib/grafana
- ${MTT_SITE_MONITORING_WORKDIR:-./monitoring}/grafana/dashboards:/etc/grafana/dashboards:ro
- ${MTT_SITE_MONITORING_WORKDIR:-./monitoring}/grafana/provisioning:/etc/grafana/provisioning:ro
- ${SEED_SITE_MONITORING_WORKDIR:-./monitoring}/grafana/dashboards:/etc/grafana/dashboards:ro
- ${SEED_SITE_MONITORING_WORKDIR:-./monitoring}/grafana/provisioning:/etc/grafana/provisioning:ro
environment:
GF_LOG_MODE: console
GF_PATHS_PROVISIONING: "/etc/grafana/provisioning"
GF_SERVER_HTTP_PORT: ${MTT_SITE_MONITORING_PORT:-3001}
GF_SERVER_HTTP_PORT: ${SEED_SITE_MONITORING_PORT:-3001}
GF_SERVER_PROTOCOL: "http"
GF_SERVER_DOMAIN: ${MTT_SITE_DNS:-localhost:3001}
GF_SERVER_ROOT_URL: ${MTT_SITE_HOSTNAME:-http://localhost}/.metrics
GF_SERVER_DOMAIN: ${SEED_SITE_DNS:-localhost:3001}
GF_SERVER_ROOT_URL: ${SEED_SITE_HOSTNAME}/.metrics
GF_SERVER_SERVE_FROM_SUB_PATH: True

volumes:
Expand Down
2 changes: 1 addition & 1 deletion frontend/apps/web/app/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from "fs/promises";
import {join} from "path";
import {z} from "zod";

const configPath = join(process.cwd(), "config.json");
const configPath = join(process.env.DATA_DIR || process.cwd(), "config.json");

const configSchema = z.object({
availableRegistrationSecret: z.string().optional(),
Expand Down
20 changes: 10 additions & 10 deletions website_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ hostname="${hostname%/}"
mkdir -p ${workspace}
rm -f ${workspace}/deployment.log
touch ${workspace}/deployment.log
curl -s -o ${workspace}/hmsite.yml https://raw.githubusercontent.com/MintterHypermedia/mintter/main/docker-compose.yml
curl -s -o ${workspace}/hmsite.yml https://raw.githubusercontent.com/seed-hypermedia/seed/main/docker-compose.yml

install_docker
if [ -n "$profile" ]; then
Expand All @@ -72,15 +72,15 @@ if [ -n "$profile" ]; then
mkdir -p ${workspace}/monitoring/grafana/provisioning/datasources
mkdir -p ${workspace}/monitoring/prometheus
fi
docker stop nextjs hmsite proxy grafana prometheus 2> ${workspace}/deployment.log 1> ${workspace}/deployment.log || true
docker rm nextjs hmsite proxy grafana prometheus 2> ${workspace}/deployment.log 1> ${workspace}/deployment.log || true
docker stop seed-site seed-daemon proxy grafana prometheus 2> ${workspace}/deployment.log 1> ${workspace}/deployment.log || true
docker rm seed-site seed-daemon proxy grafana prometheus 2> ${workspace}/deployment.log 1> ${workspace}/deployment.log || true

dns=$(echo "MTT_SITE_HOSTNAME=${hostname}" | sed -n 's/.*MTT_SITE_HOSTNAME=http[s]*:\/\/\([^/]*\).*/\1/p')
dns=$(echo "SEED_SITE_HOSTNAME=${hostname}" | sed -n 's/.*SEED_SITE_HOSTNAME=http[s]*:\/\/\([^/]*\).*/\1/p')

mkdir -p ${workspace}/proxy

cat << BLOCK > ${workspace}/proxy/CaddyFile
{\$MTT_SITE_HOSTNAME}
{\$SEED_SITE_HOSTNAME}
@ipfsget {
method GET HEAD OPTIONS
Expand All @@ -99,7 +99,7 @@ cat << BLOCK > ${workspace}/proxy/CaddyFile
reverse_proxy @wellknown hmsite:{\$HM_SITE_BACKEND_GRPCWEB_PORT:56001}
reverse_proxy /.metrics* grafana:{\$MTT_SITE_MONITORING_PORT:3001}
reverse_proxy /.metrics* grafana:{\$SEED_SITE_MONITORING_PORT:3001}
route @version {
rewrite /.well-known/hypermedia-site/version /debug/version
Expand All @@ -108,7 +108,7 @@ route @version {
reverse_proxy @ipfsget hmsite:{\$HM_SITE_BACKEND_GRPCWEB_PORT:56001}
reverse_proxy * nextjs:{\$MTT_SITE_LOCAL_PORT:3000}
reverse_proxy * nextjs:{\$SEED_SITE_LOCAL_PORT:3000}
BLOCK

if [ $auto_update -eq 1 ]; then
Expand All @@ -120,10 +120,10 @@ if [ $auto_update -eq 1 ]; then
docker run -d --restart unless-stopped --name autoupdater -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --include-restarting -i 300 nextjs hmsite >/dev/null 2>&1
fi

MTT_SITE_DNS="$dns" MTT_SITE_TAG="$tag" MTT_SITE_ALLOW_PUSH="$allow_push" MTT_SITE_HOSTNAME="$hostname" MTT_SITE_PROXY_CONTAINER_NAME="proxy" MTT_SITE_NEXTJS_CONTAINER_NAME="nextjs" MTT_SITE_DAEMON_CONTAINER_NAME="hmsite" MTT_SITE_MONITORING_WORKDIR="${workspace}/monitoring" MTT_SITE_MONITORING_PORT="$MTT_SITE_MONITORING_PORT" docker compose -f ${workspace}/hmsite.yml --profile "$profile" up -d --pull always --quiet-pull 2> ${workspace}/deployment.log || true
# MTT_SITE_DNS="$dns" MTT_SITE_HOSTNAME="$hostname" MTT_SITE_PROXY_CONTAINER_NAME="proxy" MTT_SITE_NEXTJS_CONTAINER_NAME="nextjs" MTT_SITE_DAEMON_CONTAINER_NAME="hmsite" docker compose -f ${workspace}/hmsite.yml up -d --pull always --quiet-pull 2> ${workspace}/deployment.log || true
mkdir -p ~/.seed-site/web
echo '{"availableRegistrationSecret": "123"}' > ~/.seed-site/web/config.json

timeout 15 docker logs -f hmsite 2> /dev/null | sed '/Site Invitation secret token: / q' | awk -F ': ' '{print $2}'
SEED_SITE_DNS="$dns" SEED_SITE_TAG="$tag" SEED_SITE_ALLOW_PUSH="$allow_push" SEED_SITE_HOSTNAME="$hostname" SEED_SITE_PROXY_CONTAINER_NAME="proxy" SEED_SITE_MONITORING_WORKDIR="${workspace}/monitoring" SEED_SITE_MONITORING_PORT="$SEED_SITE_MONITORING_PORT" docker compose -f ${workspace}/hmsite.yml --profile "$profile" up -d --pull always --quiet-pull 2> ${workspace}/deployment.log || true

rm -f ${workspace}/hmsite.yml
exit 0

0 comments on commit c6c172b

Please sign in to comment.