Skip to content

Commit ce5e15f

Browse files
committed
Minor cleanup
1 parent 71e6917 commit ce5e15f

File tree

10 files changed

+50
-29
lines changed

10 files changed

+50
-29
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ If these formatters are not used, the CI pipeline will create a commit with the
4444

4545
### Code Linting
4646

47-
The `frontend` for this project uses [ESLint](https://eslint.org/) for linting. The `backend` uses [GolangCI](https://golangci-lint.run/) for linting.
47+
The following code linters are required for this project:
48+
49+
- [ESLint](https://eslint.org/) for all frontend code
50+
- [GolangCI](https://golangci-lint.run/) for all backend code
51+
52+
If these linters are not used, the CI pipeline will fail if linting errors are found.
4853

4954
## Structure
5055

@@ -87,7 +92,7 @@ First, install the **NVIDIA Container Toolkit** by following the instructions [h
8792

8893
First, install GPU support. On Windows it is only available in Docker Desktop via **WSL 2** backend Paravirtualization, to enable it, follow the instructions [here](https://docs.docker.com/desktop/features/gpu/)
8994

90-
#### Starting
95+
### Starting
9196

9297
Then, run:
9398

@@ -139,6 +144,15 @@ To stop all services, run:
139144
docker-compose -f docker-compose-cpu.yaml down
140145
```
141146

147+
### Sample `.env` file
148+
149+
```env
150+
JWT_SECRET=dev_secret
151+
SURREALDB_USERNAME=root
152+
SURREALDB_PASSWORD=root
153+
REDIS_PASSWORD=password
154+
```
155+
142156
### Starting the frontend service
143157

144158
Ensure all dependencies are installed by running in the `web` directory:

build/package/prod/backend.prod.dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ RUN go mod download
1111
# Copy the rest of the application source code into the container
1212
COPY . .
1313

14+
# Copy the .env file into the container
15+
COPY .env .env
16+
17+
1418
# Build the Go application
1519
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/tokenbase ./cmd/tokenbase
1620

cmd/tokenbase/tokenbase.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ func main() {
8484
// Sleep to wait for Docker containers to start.
8585
time.Sleep(5 * time.Second)
8686

87-
// Load in env variables from .env file.
87+
// Load in environment variables.
8888
err := godotenv.Load(".env")
89+
8990
if err != nil {
90-
panic("Failed to load .env file")
91+
panic("failed to load environment variables")
9192
}
9293

9394
// Connect to SurrealDB over the Docker network.

docker-compose-cpu.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ services:
4444
dockerfile: ./build/package/redis.dockerfile
4545
ports:
4646
- "6379:6379"
47-
environment:
48-
- REDIS_PASSWORD=password
47+
env_file:
48+
- ./.env
4949
networks:
5050
- app-network
5151

docker-compose-prod.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ services:
5151
dockerfile: ./build/package/redis.dockerfile
5252
ports:
5353
- "6379:6379"
54-
environment:
55-
- REDIS_PASSWORD=password
54+
env_file:
55+
- ./.env
5656
networks:
5757
- app-network
5858

docker-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ services:
5151
dockerfile: ./build/package/redis.dockerfile
5252
ports:
5353
- "6379:6379"
54-
environment:
55-
- REDIS_PASSWORD=password
54+
env_file:
55+
- ./.env
5656
networks:
5757
- app-network
5858

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ require (
66
github.com/go-chi/chi/v5 v5.2.1
77
github.com/go-chi/cors v1.2.1
88
github.com/golang-jwt/jwt/v5 v5.2.2
9+
github.com/joho/godotenv v1.5.1
910
github.com/mitchellh/mapstructure v1.5.0
1011
github.com/surrealdb/surrealdb.go v0.3.2
1112
)
1213

1314
require (
1415
github.com/cespare/xxhash/v2 v2.3.0 // indirect
1516
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
16-
github.com/joho/godotenv v1.5.1 // indirect
1717
github.com/stretchr/testify v1.10.0 // indirect
1818
)
1919

internal/utils/constants.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package utils
22

3-
import (
4-
"os"
5-
)
6-
73
const BackendEndpoint = ":8090"
84

95
// Account constraints.
@@ -27,20 +23,8 @@ var (
2723
SdbName = "tokenbaseDB"
2824
)
2925

30-
func GetSdbUsername() string {
31-
return os.Getenv("SDB_USERNAME")
32-
}
33-
34-
func GetSdbPassword() string {
35-
return os.Getenv("SDB_PASSWORD")
36-
}
37-
3826
// Redis connection details.
3927
var (
4028
RdbDockerEndpoint = "redis:6379"
4129
RdbDatabase = 0
4230
)
43-
44-
func GetRdbPassword() string {
45-
return os.Getenv("RDB_PASSWORD")
46-
}

internal/utils/env.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package utils
2+
3+
import "os"
4+
5+
func GetJwtSecret() string {
6+
return os.Getenv("JWT_SECRET")
7+
}
8+
9+
func GetSdbUsername() string {
10+
return os.Getenv("SURREALDB_USERNAME")
11+
}
12+
13+
func GetSdbPassword() string {
14+
return os.Getenv("SURREALDB_PASSWORD")
15+
}
16+
17+
func GetRdbPassword() string {
18+
return os.Getenv("REDIS_PASSWORD")
19+
}

internal/utils/jwt.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import (
66

77
"github.com/golang-jwt/jwt/v5"
88
"github.com/mitchellh/mapstructure"
9-
"os"
109
)
1110

1211
var (
1312
jwtLifetime = time.Hour * 24
14-
jwtSecretKey = []byte(os.Getenv("JWT_SECRET"))
13+
jwtSecretKey = []byte(GetJwtSecret())
1514
)
1615

1716
// Generates a JWT for a user.

0 commit comments

Comments
 (0)