1
1
# Full-stack Clojure/Script app with deployment using Kamal
2
2
3
- This project aims to show a setup of Clojure/Script web-application that
4
- uses PostgreSQL as a database. Also, there is a config for
5
- deployment the app with Kamal on ** a single server** .
3
+ This project demonstrates the setup of a Clojure/Script web application that uses PostgreSQL as its database.
4
+ It also includes configuration for deploying the app with Kamal on ** a single server** .
6
5
7
6
Key backend libs:
8
7
- Integrant
@@ -27,47 +26,49 @@ Other tools:
27
26
28
27
## The app
29
28
30
- It's a setup for Clojure/Script application with an example API route for getting
31
- movies list and showing them on the main page.
29
+ This setup provides a Clojure/Script web application with an example API route for fetching
30
+ a list of movies and displaying them on the main page.
31
+
32
+ ![ App main page] ( /docs/app_page.png )
32
33
33
34
## Deploy: TL;DR
34
35
35
- First deploy :
36
+ First deployment :
36
37
37
38
``` shell
38
- ./kamal.sh envify --skip-push # then fill all variables in newly created .env file
39
+ ./kamal.sh envify --skip-push # then fill all variables in the newly created ` .env` file
39
40
./kamal.sh server bootstrap
40
41
ssh
[email protected] ' docker network create traefik'
41
42
ssh
[email protected] ' mkdir -p /root/letsencrypt && touch /root/letsencrypt/acme.json && chmod 600 /root/letsencrypt/acme.json'
42
43
./kamal.sh setup
43
44
./kamal.sh app exec ' java -jar standalone.jar migrations'
44
45
```
45
46
46
- Then any subsequent deploy from local machine:
47
+ For subsequent deployments from the local machine:
47
48
48
49
``` shell
49
50
./kamal.sh deploy
50
51
```
51
52
52
- or push to ` master ` - branch.
53
+ or push to the master branch.
53
54
54
55
## Deploy: step-by-step
55
56
56
57
### Requirements
57
58
58
- Make sure you have Docker [ installed] ( https://docs.docker.com/engine/install/ ) on your machine.
59
+ Ensure you have Docker [ installed] ( https://docs.docker.com/engine/install/ ) on your machine.
59
60
60
- We are going to use predefined command to run dockerized version of Kamal,
61
- so in this case you don' t need to install anything else to deploy your app.
61
+ We will use a predefined command to run a dockerized version of Kamal,
62
+ so you don’ t need to install anything else to deploy your app.
62
63
63
64
``` shell
64
65
./kamal.sh version
65
66
```
66
67
67
68
---
68
69
69
- :information_source : ** Note** : _ Alternatively you can install Kamal as ruby gem
70
- and use just ` kamal ` command instead of dockerized version:_
70
+ :information_source : ** Note** : _ Alternatively you can install Kamal as Ruby gem
71
+ and use the ` kamal ` command instead of dockerized version:_
71
72
72
73
Install [ mise-en-place] ( https://mise.jdx.dev/getting-started.html#quickstart ) (or [ asdf] ( https://asdf-vm.com/guide/getting-started.html ) ),
73
74
add ` ruby 3.3.0 ` to ` .tool-versions ` file and run:
@@ -83,16 +84,17 @@ kamal version
83
84
84
85
#### Setup environment variables
85
86
86
- Run command ` envify ` to create ` .env ` with all required empty variables:
87
+ Run command ` envify ` to create a ` .env ` with all required empty variables:
87
88
88
89
``` shell
89
90
./kamal.sh envify --skip-push
90
91
```
91
92
92
- _ Parameter ` --skip-push ` is needed to do not push ` .env ` -file to server._
93
+ _ The ` --skip-push ` parameter prevents the ` .env ` file from being pushed to the server._
94
+
95
+ Now, you can fill all environment variables in the .env file with actual values for deployment on the server.
96
+ Here’s an example:
93
97
94
- Now, you can fill all env vars in ` .env ` -file with actual values for deployment on a server.
95
- Let's check an example:
96
98
``` shell
97
99
# Generated by kamal envify
98
100
# DEPLOY
@@ -112,10 +114,10 @@ POSTGRES_PASSWORD=secret-db-password
112
114
```
113
115
114
116
Notes:
115
- - ` SERVER_IP ` - the IP of the server you wnat to deploy tour app, you should be able to connect to it using ssh-keys.
116
- - ` REGISTRY_USERNAME ` and ` REGISTRY_PASSWORD ` - credentials for docker registry, in our case we are using ` ghcr.io ` , but it can be anything .
117
+ - ` SERVER_IP ` - the IP of the server you want to deploy your app, you should be able to connect to it using ssh-keys.
118
+ - ` REGISTRY_USERNAME ` and ` REGISTRY_PASSWORD ` - credentials for docker registry, in our case we are using ` ghcr.io ` , but it can be any registry .
117
119
- ` TRAEFIK_ACME_EMAIL ` - email for register TLS-certificate with Let's Encrypt and Traefik.
118
- - ` APP_DOMAIN ` - domain of your app, should be configured to point out to ` SERVER_IP ` .
120
+ - ` APP_DOMAIN ` - domain of your app, should be configured to point to ` SERVER_IP ` .
119
121
- ` clojure-kamal-example-db ` - this is the name of the database container from accessories section of ` deploy/config.yml ` file.
120
122
- We duplicated database credentials to set up database container and use ` DATABASE_URL ` in the app.
121
123
@@ -129,37 +131,37 @@ Install Docker on a server:
129
131
./kamal.sh server bootstrap
130
132
```
131
133
132
- Create docker network to have access to database container from the app by container name
133
- and directory for Let' s Encrypt certificates:
134
+ Create a Docker network for access to the database container from the app by container name
135
+ and a directory for Let’ s Encrypt certificates:
134
136
135
137
``` shell
136
138
ssh
[email protected] ' docker network create traefik'
137
139
ssh
[email protected] ' mkdir -p /root/letsencrypt && touch /root/letsencrypt/acme.json && chmod 600 /root/letsencrypt/acme.json'
138
140
```
139
141
140
- Set up Traefik, database, environment variables and run app on a server:
142
+ Set up Traefik, the database, environment variables and run app on a server:
141
143
142
144
``` shell
143
145
./kamal.sh setup
144
146
```
145
147
146
- The app is deployed on the server, but it is not fully functioning yet, we need to run database migrations:
148
+ The app is deployed on the server, but it is not fully functional yet. You need to run database migrations:
147
149
148
150
``` shell
149
151
./kamal.sh app exec ' java -jar standalone.jar migrations'
150
152
```
151
153
152
- Now, we the application fully deployed on the server.
154
+ Now, the application is fully deployed on the server.
153
155
154
156
### Regular deploy
155
157
156
- Then, next time for deploy the app from local machine, run:
158
+ For subsequent deployments from the local machine, run:
157
159
158
160
``` shell
159
161
./kamal.sh deploy
160
162
```
161
163
162
- Or just push to the master, there is a GitHub Actions pipeline that does
164
+ Or just push to the master branch , there is a GitHub Actions pipeline that does
163
165
the deployment automatically ` .github/workflows/deploy.yaml ` .
164
166
165
167
### Setup CI for deployment
0 commit comments