Merge pull request #36 from cgzirim/development

Dockerize App
This commit is contained in:
Chigozirim Igweamaka 2025-04-08 02:49:12 +01:00 committed by GitHub
commit 649f19b4a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 123 additions and 8 deletions

28
.dockerignore Normal file
View file

@ -0,0 +1,28 @@
# Binaries for programs and plugins
*.exe
*.ogg
*.m4a
*.zip
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
**/songs
.vscode
package-lock.json
*sqlite3
.env

7
.env.example Normal file
View file

@ -0,0 +1,7 @@
DB_TYPE=mongo
DB_USER=user
DB_PASS=password
DB_NAME=seek-tune
DB_HOST=192.168.0.1
DB_PORT=27017
REACT_APP_BACKEND_URL=http://localhost:5000

2
.gitignore vendored
View file

@ -26,3 +26,5 @@ go.work
.vscode
package-lock.json
*sqlite3
.env

33
Dockerfile Normal file
View file

@ -0,0 +1,33 @@
# build react
FROM node:20-alpine AS build_react_stage
RUN mkdir -p /home/react
WORKDIR /home/react
COPY client/package.json ./
RUN npm install
COPY client/ ./
ARG REACT_APP_BACKEND_URL
ENV REACT_APP_BACKEND_URL=${REACT_APP_BACKEND_URL}
RUN npm run build
# build go
FROM golang:1.21.6
WORKDIR /home/seek-tune
COPY server/go.mod server/go.sum ./
RUN go mod download
COPY server/ ./
ENV ENV=production
RUN mkdir -p static
COPY --from=build_react_stage /home/react/build static
RUN go build -o seek-tune
EXPOSE 5000
CMD [ "/home/seek-tune/seek-tune", "serve" ]

View file

@ -25,22 +25,35 @@ Additionally, it currently only supports song files in WAV format.
- NPM: To run the client (frontend).
### Steps
Clone the repository:
📦 Clone the repository:
```
git clone https://github.com/cgzirim/seek-tune.git
cd seek-tune
```
#### 🐳 Set Up with Docker
Prerequisites: [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/)
1. Build and run the application:
```Bash
docker-compose up --build
```
Visit the app at http://localhost:8080
2. To stop the application:
```Bash
docker-compose down
```
#### 💻 Set Up Natively
Install dependencies for the backend
```
cd seek-tune
cd server
go get ./...
```
Install dependencies for the client
```
cd seek-tune/client
cd client
npm install
```
## Usage :bicyclist:
## Usage (Native Setup) :bicyclist:
#### ▸ Start the Client App 🏃‍♀️‍➡️
```
@ -51,7 +64,7 @@ npm start
#### ▸ Start the Backend App 🏃‍♀️
In a separate terminal window:
```
cd seek-tune
cd server
go run *.go serve [-proto <http|https> (default: http)] [-port <port number> (default: 5000)]
```
#### ▸ Download a Song 📥

View file

@ -1,7 +1,7 @@
version: 0.0
os: linux
files:
- source: /
- source: server/
destination: /home/ubuntu/song-recognition
hooks:
BeforeInstall:

31
docker-compose.yml Normal file
View file

@ -0,0 +1,31 @@
version: '3.1'
volumes:
seek-tune-db:
seek-tune-songs:
services:
seek-tune:
image: 'seek-tune'
restart: unless-stopped
ports:
- 8080:5000
environment:
DB_TYPE: ${DB_TYPE:-sqlite}
DB_USER: ${DB_USER:-root}
DB_PASSWORD: ${DB_PASSWORD:-password}
DB_NAME: ${DB_NAME:-seek_tune_db}
DB_HOST: ${DB_HOST:-localhost}
DB_PORT: ${DB_PORT:-27017}
REACT_APP_BACKEND_URL: ${REACT_APP_BACKEND_URL:-http://localhost:8080}
build:
context: .
args:
REACT_APP_BACKEND_URL: ${REACT_APP_BACKEND_URL:-http://localhost:8080}
volumes:
- seek-tune-db:/home/seek-tune/db
- seek-tune-songs:/home/seek-tune/songs

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
start_server() {
cd /home/ubuntu/song-recognition
cd /home/ubuntu/song-recognition/server
export SERVE_HTTPS="true"
export CERT_KEY="/etc/letsencrypt/live/localport.online/privkey.pem"

View file

@ -160,6 +160,7 @@ func serve(protocol, port string) {
func serveHTTP(socketServer *socketio.Server, serveHTTPS bool, port string) {
http.Handle("/socket.io/", socketServer)
http.Handle("/", http.FileServer(http.Dir("static")))
if serveHTTPS {
httpsAddr := ":" + port

View file

@ -46,7 +46,7 @@ func NewDBClient() (DBClient, error) {
return NewMongoClient(dbUri)
case "sqlite":
return NewSQLiteClient("db.sqlite3")
return NewSQLiteClient("db/db.sqlite3")
default:
return nil, fmt.Errorf("unsupported database type: %s", DBtype)

BIN
server/songs/Chiquitita.wav Normal file

Binary file not shown.

Binary file not shown.

BIN
server/songs/Jolene.wav Normal file

Binary file not shown.