- Install and run Postgres. PostgresApp does a great job.
- Clone this repo
- Set up the enivronment variables found in
env_example
.- Be sure to remember the admin email and password for step 5
- You can set runtime environment variables by editting Xcode’s project scheme.
- Product > Scheme > Edit Scheme. Then go to Run > Arguments > Environment Variables
- Build and run
- Explore the API using RapidAPI for Mac. Open the CoffeeServer.paw file to find various routes. Many routes are admin protected. You’ll need your login info from step 3
On the first run, the super user will be created. You’ll need the super user account to do most create update and delete actions.
- Some type of constantly internet connected server-like host
- ssh into your host server
- Install git. Documentation
- Install Docker. Documentation
- Clone this repo into a reasonable directory. Ex:
/home/
The entire service fleet (app, database, and Caddy proxy) are configured with the docker-compose
file.
From the outside in:
A request to your service will first reach Caddy which knows that your server name — say, CoffeeCoffee.world
— exists and should proxy the request to the app. The app is a Vapor server written in Swift 5.7. It connects to the database which is Postres to save and fetch data.
- Configure the
Caddyfile
.- Copy the example file
cp Caddyfile-example Caddyfile
- Open Caddyfile in your text editor and change the
example.com
domain name to whichever domain you’re using. Note that this doesn’t include the url scheme — just the stuff after://
.
- Copy the example file
- Configure the
.env
file- Copy the example file
cp env_example .env
- Open
.env
in your text editor and add your values for each value
- Copy the example file
- Boot the service
- If this is the first run then you’ll need to build the app image:
docker compose up --build -d
- If the build fails for any reason, you can build on your local machine and push to docker hub. Your dev sandbox is also likely a great deal faster than a typical web host.
- In standard operation
docker compose up -d
- If this is the first run then you’ll need to build the app image:
- Run any migrations
- If this is the first run then you must run the database migrations:
docker compose run migrate
- There is no effect to run migrations that have already been run
- The only time you won’t need to run migrations is if you’re certain that the data models haven’t changed
- If this is the first run then you must run the database migrations:
At this point the service fleet should be running and connected to the database.
- Assert that the appropriate docker containers are running.
docker ps
should have three running containers. coffee-server:latest, caddy:XXXX, and postgres:XXXX
- Assert
/healthcheck
is OK. From inside your ssh session on the server…curl "http://127.0.0.1:8080/healthcheck"
should have output similiar to:OK. Database Check: Event count = 0
- Assert the service is reachable at your domain. Close your server ssh session and try…
curl "http://EXAMPLE.COM/healthcheck"
should be OK.
- Finally, assert that Let’s Encrypt Caddy server is working.
curl "https://EXAMPLE.COM/healthcheck"
should also be OK.
At this point, using a web browser and opening your URL should see the “Coffee”.