ataractic
ataractic2y ago

Looking to deploy Deno Fresh on VPS using port 443

Hello! I have two questions, I used saaskit as a base. However fresh's start function is using serve() and not serveTls(). The problem is I cannot expose on 443 since I can't provide certificate and key as start options. Any advice? Should I write a custom start function? My second question is about continuous deployment: I have setup a gitlab runner on my VPS that handles the process of running on each new commit, but unlike NPM, the deno runtime is "listening" and the pipeline stays in "running" state. Is there any solution to this? Thank you!
6 Replies
NeTT
NeTT2y ago
You can use a reverse proxy like Nginx to point your 443 to your project port
server {
listen 80;
server_name YOUR_URL_HERE;
location / {
proxy_pass http://localhost:YOUR_PORT;
}
}

server {
listen 443 ssl;
server_name YOUR_URL_HERE;
ssl_certificate /PATH/TO/YOUR/CERT.pem;
ssl_certificate_key /PATH/TO/YOUR/KEY.pem;
ssl_prefer_server_ciphers on;

location / {
proxy_pass http://localhost:YOUR_PORT;
}
}
server {
listen 80;
server_name YOUR_URL_HERE;
location / {
proxy_pass http://localhost:YOUR_PORT;
}
}

server {
listen 443 ssl;
server_name YOUR_URL_HERE;
ssl_certificate /PATH/TO/YOUR/CERT.pem;
ssl_certificate_key /PATH/TO/YOUR/KEY.pem;
ssl_prefer_server_ciphers on;

location / {
proxy_pass http://localhost:YOUR_PORT;
}
}
config like this should do
ataractic
ataracticOP2y ago
Thanks a lot! lemme try... I just stumbled upon your previous post, so I will try to resolve the second problem using a daemon and post the CI/CD script here It worked! Installed nginx, bought a cheap 5 years certificate and added it to the VPS, now my website is accessible using https! <:party_deno:1035517691517218847> I also found a way to fix my CI/CD issues, and I think it can be of general interest
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

int print_help(int status) {
printf("usage: ./daemonize <bash command>\n\n");

return status;
}

/**
* @brief Executes a bash command as a background task (daemon)
* @param argc Argument count
* @param argv Argument vector
* @return 0 on success, non-zero on failure
*/
int main(int argc, char** argv) {
int status= 0;

if (argc != 2) {
printf("error: invalid syntax\n");
return print_help(1);
}

status = daemon(1, 0);

if (system(argv[1]) != 0) {
return 1;
}

return status;
}
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

int print_help(int status) {
printf("usage: ./daemonize <bash command>\n\n");

return status;
}

/**
* @brief Executes a bash command as a background task (daemon)
* @param argc Argument count
* @param argv Argument vector
* @return 0 on success, non-zero on failure
*/
int main(int argc, char** argv) {
int status= 0;

if (argc != 2) {
printf("error: invalid syntax\n");
return print_help(1);
}

status = daemon(1, 0);

if (system(argv[1]) != 0) {
return 1;
}

return status;
}
I created this simple C program that daemonizes a bash command so it can exit the CI/CD pipeline correctly. just run the following command
./daemonize "deno task start"
./daemonize "deno task start"
Here is my gitlab-ci.yml continuous deployment script
stages: # List of stages for jobs, and their order of execution
- deploy

deploy-job: # This job runs in the deploy stage.
stage: deploy
environment: production
script:
# Install deno
- curl -fsSL https://deno.land/x/install/install.sh | sh
- export DENO_INSTALL="/home/gitlab-runner-user/.deno"
- export PATH="$DENO_INSTALL/bin:$PATH"

# Mandatory for prod
- export DENO_DEPLOYMENT_ID="$(git rev-parse HEAD)"

# Test
- deno fmt
- deno task ok

# Kill previous running instance (kill process "deno" that will cause process "daemonize" to terminate), it may fail if there is no deno process running, this is why we add '|| true'
- killall -r "deno" || true

# Run new instance
- ./daemonize "deno task prod"
stages: # List of stages for jobs, and their order of execution
- deploy

deploy-job: # This job runs in the deploy stage.
stage: deploy
environment: production
script:
# Install deno
- curl -fsSL https://deno.land/x/install/install.sh | sh
- export DENO_INSTALL="/home/gitlab-runner-user/.deno"
- export PATH="$DENO_INSTALL/bin:$PATH"

# Mandatory for prod
- export DENO_DEPLOYMENT_ID="$(git rev-parse HEAD)"

# Test
- deno fmt
- deno task ok

# Kill previous running instance (kill process "deno" that will cause process "daemonize" to terminate), it may fail if there is no deno process running, this is why we add '|| true'
- killall -r "deno" || true

# Run new instance
- ./daemonize "deno task prod"
I hope it can be useful to someone, I'll put this short daemonize program on my gitlab!
NeTT
NeTT2y ago
yep will definitely be useful I personally just use webhooks for CD
ataractic
ataracticOP2y ago
may i ask how do you use webhooks for your cd?
NeTT
NeTT2y ago
I'm lazy with a lot of stuff so Servers receives a request on push and manually runs git pull and systemctl restart xxx.service
ataractic
ataracticOP2y ago
could have done that lol

Did you find this page helpful?