Skip to content

Commit

Permalink
Merge pull request #5 from Favo02/deploy
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
Favo02 authored Apr 21, 2024
2 parents 0488bbf + 25451fa commit 3afc26b
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 66 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/deploy-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: deploy-backend

on:
push:
branches: [ "main" ]

steps:
- uses: actions/checkout@v3
name: Check out code

- uses: mr-smithers-excellent/docker-build-push@v6
name: Build & push Docker image
with:
image: cess-advisor-backend
tags: latest
registry: ghcr.io
dockerfile: Dockerfile
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
20 changes: 0 additions & 20 deletions .github/workflows/deploy.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ package
.env
.env.*
!.env.example
!.env.template
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

**Cess Advisor** 🐪🚽 is a _stupid_ yet really _useful_ web app that helps you find a _suitable toilet_ when you are in a hurry.


## Tech stack

In short: **OCaml** 🐪 (Sihl) + **JavaScript** 🤢 (Svelte) + **PostgreSQL** 🐘 + Docker 🐳 + GitHub Actions 🚀
TL;DR: **OCaml** 🐪 (Sihl) + **JavaScript** 🤢 (Svelte) + **PostgreSQL** 🐘

> [!TIP]
> If you want to preserve your mental health, you should **NOT** write JavaScript code _(and frontends in general)_. OCaml is just better.
Expand All @@ -17,25 +16,47 @@ In short: **OCaml** 🐪 (Sihl) + **JavaScript** 🤢 (Svelte) + **PostgreSQL**

- Backend: **OCaml** 🐪
- [Sihl](https://github.com/oxidizing/sihl): OCaml framework for building web apps
- [Opium](https://github.com/rgrinberg/opium/): OCaml framework for managing HTTP requests
- [Opium](https://github.com/rgrinberg/opium/): OCaml library for managing HTTP requests
- [Caqti](https://github.com/paurkedal/ocaml-caqti): OCaml library for interacting with databases
- [Yojson](https://github.com/ocaml-community/yojson): OCaml library for JSON serialization
- [Validate](https://github.com/Axot017/validate): OCaml library for validating schemas

- Frontend: **JavaScript** ⚛️
- [Sveltekit](https://kit.svelte.dev/): JavaScript framework for frontend web development
- Frontend: **JavaScript** 🤢
- [Sveltekit](https://kit.svelte.dev/): JavaScript framework for web development
- [Tailwind CSS](https://tailwindcss.com/): CSS framework
- [DaisyUI](https://daisyui.com/): Tailwind components library

- Database: 🐘
- [PostgreSQL](https://www.postgresql.org/): relational database

- Deployment: 🐳
- [Docker](https://www.docker.com/): containerization
- [GitHub Actions](https://docs.github.com/en/actions): CI/CD
</details>

## Deployment

TL;DR: **Docker** 🐳 + **GitHub Actions** 🤖 for backend and **Cloudflare Pages** ☁️ for frontend

<details>
<summary>Detailed deployment</summary>

- Backend: **Docker** 🐳 + **GitHub Actions** 🤖
- each time a commit is pushed to the `main` branch, `deploy` GitHub action is triggered
- the action builds the Docker image and pushes it to the GitHub container registry
- the image is then pulled by my homelab server (periodically checked with Watchtower) and the container is started
- the backend is available at [https://cessadvisorapi.favo02.dev](https://cessadvisorapi.favo02.dev)

- **Frontend**: **Cloudflare Pages** ☁️
- each time a commit is pushed to the `main` branch, the Cloudflare pages integration detects the change
- the integration builds the Sveltekit app with some magic
- the frontend is available at [https://cessadvisor.pages.dev](https://cessadvisor.pages.dev) (and [https://cessadvisor.favo02.dev](https://cessadvisor.favo02.dev))

</details>

## Contributing

Each contribution is **welcome**, especially building alteranive better frontends _(if you are brave enough to write JavaScript code)_ that uses the same API.

Please follow the [conventions](#conventions) below.

## Conventions

<details>
Expand Down
14 changes: 7 additions & 7 deletions backend/backend.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ doc: "https://github.com/Favo02/cess-advisor"
bug-reports: "https://github.com/Favo02/cess-advisor/issues"
depends: [
"ocaml" {>= "5.0.0"}
"dune" {>= "3.10" & >= "3.15.0"}
"sihl" {>= "3.0.5"}
"caqti-driver-postgresql" {>= "2.1.1"}
"lwt_ppx" {>= "2.1.0"}
"ppx_yojson_conv" {>= "v0.16.0"}
"validate" {>= "1.1.0"}
"safepass" {>= "3.0"}
"dune" {>= "3.10"}
"sihl"
"caqti-driver-postgresql"
"lwt_ppx"
"ppx_yojson_conv"
"validate"
"safepass"
"odoc" {with-doc}
]
build: [
Expand Down
14 changes: 7 additions & 7 deletions backend/dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
(description "REST API for Cess Advisor, a toilet review system")
(depends
(ocaml (>= 5.0.0))
(dune (>= 3.15.0))
(sihl (>= 3.0.5))
(caqti-driver-postgresql (>= 2.1.1))
(lwt_ppx (>= 2.1.0))
(ppx_yojson_conv (>= v0.16.0))
(validate (>= 1.1.0))
(safepass (>= 3.0))))
dune
sihl
caqti-driver-postgresql
lwt_ppx
ppx_yojson_conv
validate
safepass))
2 changes: 1 addition & 1 deletion backend/src/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let auth = Web.choose ~scope: "/api" ~middlewares: [ require_login; verify_expir
Web.post "/reviews/create" Handlers.Reviews.create;
]

let router = Web.choose ~middlewares: [ logger; ] [
let router = Web.choose ~middlewares: [ logger; Opium.Middleware.allow_cors (); ] [
public;
no_auth;
auth;
Expand Down
13 changes: 0 additions & 13 deletions docker-compose.yml

This file was deleted.

7 changes: 7 additions & 0 deletions frontend/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# template for .env file

# production (the default URL is already set)
VITE_API_URL=https://cessadvisorapi.favo02.dev

# development
# VITE_API_URL=http://localhost:3000
2 changes: 1 addition & 1 deletion frontend/src/routes/+page.svelte

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/src/routes/login/+page.svelte

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/src/routes/logout/+page.svelte

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/src/routes/profile/+page.svelte

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@ import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';

export default defineConfig({
plugins: [sveltekit()],
server: {
proxy: {
'/api': 'http://localhost:3000'
}
}
plugins: [sveltekit()]
});

0 comments on commit 3afc26b

Please sign in to comment.