diff --git a/.dockerignore b/.dockerignore index d246d8d..6aa9de4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,6 +7,8 @@ node_modules # Docker specific files (if any, other than Dockerfile itself) # .dockerignore (to avoid including itself if context changes) +docker +systemd # Local development environment files .env diff --git a/README.md b/README.md index ef98a25..001ab5b 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,11 @@ For an enhanced tactile experience, Nexus Timer supports Smart Buttons based on } ``` ## Building for the production -Clone the repo +Navigate to your project directory on the server +```bash +cd /virt +``` +Clone the repository ```bash git clone --depth 1 https://gitea.virtonline.eu/2HoursProject/nexus-timer.git cd nexus-timer @@ -134,76 +138,40 @@ Build the docker image ```bash docker build -t virt-nexus-timer . ``` -Do some sanity check first: Run the app in the container +## Exposing the App Behind Traefik (Reverse Proxy) +### Review the provided docker labels and systemd service file + +Copy the example label file to its destination ```bash -docker run --rm -p 8080:80 virt-nexus-timer +cp docker/traefik.labels labels ``` -Test the web app +View the example service definition: ```bash -curl http://localhost:8080/ +cat systemd/virt-nexus-timer.service ``` -## Expose the app on Internet behind the reverse proxy (Traefik) -Create a 'labels' file for Traefik -```bash -sudo tee labels </dev/null || true' -ExecStartPre=-/usr/bin/env sh -c '/usr/bin/env docker rm virt-nexus-timer 2>/dev/null || true' - -ExecStart=/usr/bin/env docker run \ - --rm \ - --name=virt-nexus-timer \ - --network=traefik-net \ - --label-file /opt/nexus-timer/labels \ - virt-nexus-timer - -ExecStop=-/usr/bin/env sh -c '/usr/bin/env docker kill virt-nexus-timer 2>/dev/null || true' -ExecStop=-/usr/bin/env sh -c '/usr/bin/env docker rm virt-nexus-timer 2>/dev/null || true' - -Restart=always -RestartSec=30 -SyslogIdentifier=virt-nexus-timer - -[Install] -WantedBy=multi-user.target -``` -Enable the app to start when the server boots and start it now +Enable on system boot and start the service ```bash sudo systemctl enable --now virt-nexus-timer.service ``` -See the service status +Check the service status ```bash systemctl status virt-nexus-timer.service ``` -See the logs +View real-time logs ```bash journalctl -fu virt-nexus-timer.service ``` -Finally test the web app +# Test the web application +Verify that the application is accessible via HTTPS: ```bash curl https://nexus-timer.virtonline.eu -``` \ No newline at end of file +``` +Or open it in your browser: +[https://nexus-timer.virtonline.eu](https://nexus-timer.virtonline.eu) \ No newline at end of file diff --git a/docker/traefik.labels b/docker/traefik.labels new file mode 100644 index 0000000..6550fc8 --- /dev/null +++ b/docker/traefik.labels @@ -0,0 +1,8 @@ +traefik.enable=true +traefik.docker.network=traefik +traefik.http.routers.virt-nexus-timer.rule=Host("nexus-timer.virtonline.eu") +traefik.http.routers.virt-nexus-timer.service=virt-nexus-timer +traefik.http.routers.virt-nexus-timer.tls=true +traefik.http.routers.virt-nexus-timer.tls.certResolver=default +traefik.http.routers.virt-nexus-timer.entrypoints=web-secure +traefik.http.services.virt-nexus-timer.loadbalancer.server.port=80 \ No newline at end of file diff --git a/labels b/labels new file mode 100644 index 0000000..6550fc8 --- /dev/null +++ b/labels @@ -0,0 +1,8 @@ +traefik.enable=true +traefik.docker.network=traefik +traefik.http.routers.virt-nexus-timer.rule=Host("nexus-timer.virtonline.eu") +traefik.http.routers.virt-nexus-timer.service=virt-nexus-timer +traefik.http.routers.virt-nexus-timer.tls=true +traefik.http.routers.virt-nexus-timer.tls.certResolver=default +traefik.http.routers.virt-nexus-timer.entrypoints=web-secure +traefik.http.services.virt-nexus-timer.loadbalancer.server.port=80 \ No newline at end of file diff --git a/systemd/virt-nexus-timer.service b/systemd/virt-nexus-timer.service new file mode 100644 index 0000000..e7c9eee --- /dev/null +++ b/systemd/virt-nexus-timer.service @@ -0,0 +1,29 @@ +[Unit] +Description=nexus-timer (virt-nexus-timer) +Requires=docker.service +After=docker.service +DefaultDependencies=no + +[Service] +Type=simple +Environment="HOME=/root" +ExecStartPre=-/usr/bin/env sh -c '/usr/bin/env docker kill virt-nexus-timer 2>/dev/null || true' +ExecStartPre=-/usr/bin/env sh -c '/usr/bin/env docker rm virt-nexus-timer 2>/dev/null || true' + +ExecStart=/usr/bin/env docker run \ + --rm \ + --name=virt-nexus-timer \ + --log-driver=none \ + --network=traefik \ + --label-file /virt/nexus-timer/labels \ + virt-nexus-timer + +ExecStop=-/usr/bin/env sh -c '/usr/bin/env docker kill virt-nexus-timer 2>/dev/null || true' +ExecStop=-/usr/bin/env sh -c '/usr/bin/env docker rm virt-nexus-timer 2>/dev/null || true' + +Restart=always +RestartSec=30 +SyslogIdentifier=virt-nexus-timer + +[Install] +WantedBy=multi-user.target \ No newline at end of file