From 1192ca62f2f6bdd1816a3e093ca3d776d679e693 Mon Sep 17 00:00:00 2001 From: Malachy Byrne Date: Sat, 6 May 2023 22:54:41 +0100 Subject: [PATCH] Added dockerfile for backend --- src/backend/Dockerfile | 24 ++++++++++++++++++++++++ src/backend/cmd/main.go | 9 +++------ src/backend/go.mod | 4 ++-- 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 src/backend/Dockerfile diff --git a/src/backend/Dockerfile b/src/backend/Dockerfile new file mode 100644 index 0000000..8d27e9d --- /dev/null +++ b/src/backend/Dockerfile @@ -0,0 +1,24 @@ +# syntax=docker/dockerfile:1 + +FROM golang:1.20 + +# Set destination for COPY +WORKDIR /app + +# Download Go modules +COPY . ./ +RUN go mod download + +# Build +RUN CGO_ENABLED=0 GOOS=linux go build -o /panoptes cmd/main.go + +# Optional: +# To bind to a TCP port, runtime parameters must be supplied to the docker command. +# But we can document in the Dockerfile what ports +# the application is going to listen on by default. +# https://docs.docker.com/engine/reference/builder/#expose +EXPOSE 8080 + +# Run +CMD ["/panoptes"] + diff --git a/src/backend/cmd/main.go b/src/backend/cmd/main.go index 67a5e50..606565b 100644 --- a/src/backend/cmd/main.go +++ b/src/backend/cmd/main.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "log" + "os" //"bytes" "net/http" "github.com/dgrijalva/jwt-go" @@ -19,14 +20,10 @@ import ( ) const ( - host = "localhost" port = 5432 - user = "postgres" - password = "Gcvy4266" - dbname = "Panoptes" ) -var db, err = database.ConnectDB(host, port, user, password, dbname) +var db, err = database.ConnectDB(os.Getenv("db"), port, os.Getenv("db_user"), os.Getenv("db_pass"), os.Getenv("db_name")) var jwtSecret = []byte("fAHr+Hlho9qhCePEuMxLVG2i/1tiEqtocAWkcYRJx0s=") type Schema struct { @@ -115,6 +112,7 @@ func GetModules(db *sql.DB) echo.HandlerFunc { modules := make([]Module, 0) rows, err := db.Query("SELECT name, container_name FROM Module") if err != nil { + fmt.Println("test") return err } defer rows.Close() @@ -262,7 +260,6 @@ func CreateModule(c echo.Context) error { mod_id := docker.CreateModule(module) stmt, err := db.Prepare(`INSERT INTO Module (name, container_name) VALUES ($1, $2);`) if err != nil { - fmt.Println("lmao") panic(err) } _, err = stmt.Exec(module.Name, mod_id) diff --git a/src/backend/go.mod b/src/backend/go.mod index 5bd2a50..774ee4f 100644 --- a/src/backend/go.mod +++ b/src/backend/go.mod @@ -4,6 +4,8 @@ go 1.19 require ( github.com/DATA-DOG/go-sqlmock v1.5.0 + github.com/docker/docker v23.0.5+incompatible + github.com/docker/go-connections v0.4.0 github.com/labstack/echo/v4 v4.10.2 github.com/lib/pq v1.10.8 github.com/stretchr/testify v1.8.2 @@ -15,8 +17,6 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.5+incompatible // indirect - github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/google/uuid v1.3.0 // indirect