tutorials:6
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
tutorials:6 [2023/07/29 11:04] – tcmal | tutorials:6 [2023/07/29 11:10] (current) – removed tcmal | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 6. Deploying a web app ====== | ||
- | This is a pretty general guide to putting ' | ||
- | |||
- | Usually, your app will end up either at ''< | ||
- | |||
- | For now, you'll need to ask an admin if you want to use a different domain, but we're working on changing that. | ||
- | |||
- | ===== Static Sites ===== | ||
- | |||
- | If your content is going to be served the same to everyone, it's a *static web page*. This includes JS apps that, once loaded, make requests to somewhere else. | ||
- | |||
- | Deploying these is super simple - you can build them with Gitlab (if you need to) and then deploy them on our pages instance. [[tutorials: | ||
- | |||
- | ===== Any other applications ===== | ||
- | |||
- | If you have some application you need to run that generates responses dynamically, | ||
- | |||
- | ==== Getting something running ==== | ||
- | |||
- | Firstly, consider what you need to run alongside your actual app. If you need some kind of database (which is likely), you can use our managed MySQL server. See [[https:// | ||
- | |||
- | Now you need to actually deploy your code. To start with, get it running on the '' | ||
- | |||
- | The rest of the setup largely depends on your language, and framework. For Python, you'll probably want to set up a virtual environment, | ||
- | |||
- | Eventually, you should get to a point where you can run '' | ||
- | |||
- | At this point, you should test everything is working like you expect by making an SSH tunnel. From your local machine, run '' | ||
- | |||
- | ==== Exposing it to the internet ==== | ||
- | |||
- | Now you've gotten everything running within the network, it's time to put it on the internet! Before you do this, make an effort to check for any security holes or things that should only be exposed for development. | ||
- | |||
- | Now, head to the [[https:// | ||
- | |||
- | You can create a new endpoint with your domain and whatever prefix you'd like. The target IP address will be '' | ||
- | |||
- | === Endpoint options === | ||
- | |||
- | In most cases, you won't need to use HTTPs from the proxy to the target. You can test this by running '' | ||
- | |||
- | Whether you need to strip the prefix mostly depends on how configurable your application is. | ||
- | |||
- | Say your applications' | ||
- | |||
- | Many applications or frameworks will let you specify this prefix upfront and strip it on their side. This is useful because no matter if the prefix is stripped or not, your application still needs to change its links to accomodate this - a link to ''/ | ||
- | |||
- | Endpoint changes take about 5 minutes to apply, so come back after that time and check your URL to hopefully see your application! | ||
- | |||
- | If it's not working, try running '' | ||
- | |||
- | ==== Keeping it running ==== | ||
- | |||
- | By now you probably have your command running in a terminal, and another browser with it open over the internet. This is good, but at some point you'll probably want to log off and keep your application up. | ||
- | |||
- | There are a lot of ways to do this, in ascending order of complexity: | ||
- | |||
- | * Open a tmux session and run the command | ||
- | * Make a user systemd unit, and ask an admin to enable lingering | ||
- | * Use docker, and possibly some orchestrator | ||
- | |||
- | We'll skim over each of these, but feel free to ask an admin for help. | ||
- | |||
- | === Tmux === | ||
- | |||
- | This is the easiest way by far. '' | ||
- | |||
- | From the sandbox VM, run '' | ||
- | |||
- | - Start it running in this new session just like before (you' | ||
- | - Hit '' | ||
- | |||
- | Your app is now running in the background - feel free to log out and it will stay running. If you want to get back to it to see logs or stop it, run '' | ||
- | |||
- | === Systemd === | ||
- | |||
- | Systemd is a general service manager, meaning you write down how you want to run your application and it ensures that it stays running. | ||
- | |||
- | Unlike tmux, it can do things like wait for other services to come up first, or restart your service if it crashes. Unfortunately, | ||
- | |||
- | User systemd units (which a service is a type of) go in the '' | ||
- | |||
- | < | ||
- | [Unit] | ||
- | Description=Fossil user server | ||
- | After=network-online.target | ||
- | |||
- | [Service] | ||
- | WorkingDirectory=/ | ||
- | ExecStart=/ | ||
- | |||
- | [Install] | ||
- | WantedBy=default.target | ||
- | </ | ||
- | |||
- | You can find more info on systemd services [[https:// | ||
- | |||
- | Now, you can start your service using systemd: | ||
- | |||
- | < | ||
- | $ systemctl --user daemon-reload # Pick up the changes | ||
- | $ systemctl --user enable --now your-app.service # Start the service, and auto-start it when needed | ||
- | </ | ||
- | |||
- | Here are some basic commands for managing your service: | ||
- | |||
- | < | ||
- | $ journalctl --user -efu your-app.service # Get the Entire logs and Follow them | ||
- | $ systemctl --user restart your-app.service # Restart it, for example when the code has been updated | ||
- | $ systemctl --user disable --now your-app.service # Stop and no longer auto-start | ||
- | </ | ||
- | |||
- | === Docker / Orchestrators === | ||
- | |||
- | Docker is a tool for packaging up applications with all their dependencies, | ||
- | |||
- | You can use rootless docker on the sandbox VM, although you'll need an admin to enable lingering for you just like with systemd. Just detach from the docker container once you run it, and it will stay running. You can also use docker compose or any other tools you like for making docker easier. | ||
- | |||
- | You can build a docker image for your app right on the sandbox VM, or you can build it somewhere else (including from CI) and push it to the [[https:// | ||
- | |||
- | Lastly, you can use our [[howto: |
tutorials/6.1690628664.txt.gz · Last modified: 2023/07/29 11:04 by tcmal