Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] dockerize app #31

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DB_TYPE=mongo
DB_USER=user
DB_PASS=password
DB_NAME=song-recognition
DB_HOST=192.168.0.1
DB_PORT=27017
REACT_APP_BACKEND_URL=
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

# Go workspace file
go.work
/songs
**/songs/**
.vscode

package-lock.json
*sqlite3
.env
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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/ ./
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.exe

EXPOSE 5000

CMD [ "/home/seek-tune/seek-tune.exe", "serve" ]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ cd seek-tune/client
npm install
```

## Docker 🐋

Should you choose to run as a docker container, the docker compose in the root of the project can be used, to start the app with the command `docker-compose up -d`. With the first run, the docker image will be built using the Dockerfile also found in the root of the project. If you need to rebuild the image after the first run of docker compose, the image can be built with the `docker build .` (or `docker-compose up --build -d`) command from the root of the project.

*Note: Only the features available in the app UI are available while running the docker container.*

## Usage :bicyclist:

#### ▸ Start the Client App 🏃‍♀️‍➡️
Expand Down
2 changes: 1 addition & 1 deletion appspec.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 0.0
os: linux
files:
- source: /
- source: server/
destination: /home/ubuntu/song-recognition
hooks:
BeforeInstall:
Expand Down
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3.1'
services:
seek-tune:
image: 'seek-tune'
build: .
restart: unless-stopped
ports:
- 8080:5000
env_file: .env
environment:
DB_TYPE: $DB_TYPE
DB_USER: $DB_USER
DB_PASSWORD: $DB_PASSWORD
DB_NAME: $DB_NAME
DB_HOST: $DB_HOST
DB_PORT: $DB_PORT

REACT_APP_BACKEND_URL: $REACT_APP_BACKEND_URL

volumes:
- ./songs:/home/seek-tune/songs
- ./db:/home/seek-tune/db
1 change: 1 addition & 0 deletions cmdHandlers.go → server/cmdHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,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
Expand Down
2 changes: 1 addition & 1 deletion db/client.go → server/db/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions wav/wav.go → server/wav/wav.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@ package wav

import (
"bytes"
"context"
"encoding/base64"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log/slog"
"os"
"os/exec"
"song-recognition/models"
"song-recognition/utils"
"strings"
"time"

"github.com/mdobak/go-xerrors"
)

// WavHeader defines the structure of a WAV header
Expand Down