Skip to content

Commit 714c052

Browse files
committed
docker compose setup
1 parent 57fa85c commit 714c052

File tree

6 files changed

+85
-16
lines changed

6 files changed

+85
-16
lines changed

.env.example

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
PORT=":3000"
22
CORS_SITES="*"
33
DATABASE="startersaas-db"
4-
DATABASE_URI="mongodb://localhost:27017"
4+
DATABASE_URI="mongodb://startersaas-mongo:27017"
55
JWT_SECRET="vfbhdsfnbdfsfdgfdsgfmghfdhgsdflnglsdfngker"
66
JWT_EXPIRE="1d"
7-
FRONTEND_LOGIN_URL="http://localhost:5000/auth/login"
8-
MAILER_HOST='localhost'
7+
FRONTEND_LOGIN_URL="http://localhost:3010/auth/login"
8+
MAILER_HOST='startersaas-mailhog'
99
MAILER_PORT=1025
1010
MAILER_USERNAME='foo'
1111
MAILER_PASSWORD='bar'
1212
DEFAULT_EMAIL_FROM="[email protected]"
1313
LOCALE="it"
14-
STRIPE_SECRET_KEY=sk_test_xyz
14+
STRIPE_SECRET_KEY=sk_test_XYZ
1515
TRIAL_DAYS=15
1616
PAYMENT_FAILED_RETRY_DAYS=7
1717
NOTIFIED_ADMIN_EMAIL=[email protected]
1818
FATTURA24_KEY="XYZ"
1919
FATTURA24_URL="https://www.app.fattura24.com/api/v0.3/SaveDocument"
2020
SIGNUP_WITH_ACTIVATE=true
21-
STARTER_PLAN_TYPE="basic"
21+
STARTER_PLAN_TYPE="pro"
22+
MONGO_PORT=27017
23+
REDIS_PORT=6379
2224

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.env
22
tmp/
3-
stripe.conf.json
3+
stripe.conf.json
4+
main

README.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,18 @@
22

33
This project contains everything you need to setup a fully featured SaaS API in 5 minutes.
44
# Installation
5-
Make sure you have MongoDB (4+) installed and running.
6-
7-
Then make sure you have Go installed ([download](https://golang.org/dl/)). Version `1.14` or higher is required.
5+
Copy `.env.example` into `.env` and `stripe.conf.json.example` into `stripe.conf.json`.
86

9-
Install all dependencies by running
7+
Build the application
108

119
```bash
12-
go get
10+
docker compose build
1311
```
1412

15-
Copy `.env.example` into `.env` and `stripe.conf.json.example` into `stripe.conf.json`.
16-
17-
Finally, run the APIs by typing:
13+
And finally, run the application
1814

1915
```bash
20-
go run main.go
16+
docker compose up
2117
```
2218

2319

docker-compose.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
version: "3"
2+
services:
3+
startersaas-go-api:
4+
container_name: startersaas-go-api
5+
build:
6+
context: .
7+
dockerfile: docker/dev/Dockerfile
8+
volumes:
9+
- ./:/go/src/app/
10+
- ./go.mod:/go/src/app/go.mod
11+
ports:
12+
- "3000:3000"
13+
networks:
14+
- startersaas-go-api-network
15+
depends_on:
16+
- startersaas-redis
17+
- startersaas-mongo
18+
19+
startersaas-redis:
20+
image: "redis:alpine"
21+
ports:
22+
- "${REDIS_PORT}:6379"
23+
env_file:
24+
- .env
25+
volumes:
26+
- redis:/data
27+
networks:
28+
- startersaas-go-api-network
29+
30+
startersaas-mongo:
31+
image: mongo:4.4
32+
volumes:
33+
- mongo:/data/db
34+
ports:
35+
- "${MONGO_PORT}:27017"
36+
env_file:
37+
- .env
38+
networks:
39+
- startersaas-go-api-network
40+
41+
startersaas-mailhog:
42+
image: mailhog/mailhog
43+
logging:
44+
driver: 'none' # disable saving logs
45+
ports:
46+
- 1025:1025 # smtp server
47+
- 8025:8025 # web ui
48+
networks:
49+
- startersaas-go-api-network
50+
51+
volumes:
52+
redis:
53+
mongo:
54+
55+
networks:
56+
startersaas-go-api-network:
57+
internal: true

docker/dev/Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM golang:1.17
2+
3+
WORKDIR /go/src/app/
4+
5+
COPY . .
6+
7+
RUN go mod download -x
8+
9+
RUN go get github.com/githubnemo/CompileDaemon
10+
11+
EXPOSE 3000
12+
13+
ENTRYPOINT CompileDaemon --build="go build main.go" --command="./main"

services/email.service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ func SendMail(from, subject, body string, to []string) error {
146146

147147
if os.Getenv("MAILER_HOST") != "localhost" {
148148
server.Encryption = mail.EncryptionSSLTLS
149-
server.TLSConfig = &tls.Config{InsecureSkipVerify: true}
150149
}
150+
server.TLSConfig = &tls.Config{InsecureSkipVerify: true}
151151

152152
// SMTP client
153153
smtpClient, err := server.Connect()

0 commit comments

Comments
 (0)