Added docker-compose configuration
This commit is contained in:
23
Dockerfile
23
Dockerfile
@ -1,27 +1,38 @@
|
||||
FROM node:current-alpine3.19 AS tailwind
|
||||
FROM node:current-alpine3.19 AS node_builder
|
||||
|
||||
WORKDIR /src
|
||||
COPY ./public/input.css ./public/
|
||||
COPY /public /src/public
|
||||
COPY tailwind.config.js .
|
||||
COPY ./view ./view
|
||||
COPY /view /src/view
|
||||
|
||||
RUN npm install -g tailwindcss
|
||||
RUN npm install -g javascript-obfuscator
|
||||
RUN npx tailwindcss -i ./public/input.css -o ./public/output.css
|
||||
RUN javascript-obfuscator ./public/upload.js --compact true --self-defending true --output ./public/upload_obfuscated.js
|
||||
RUN javascript-obfuscator ./public/validatePassword.js --compact true --self-defending true --output ./public/validatePassword_obfuscated.js
|
||||
|
||||
FROM golang:1.22.2-alpine3.19 AS go_builder
|
||||
|
||||
WORKDIR /src
|
||||
COPY . .
|
||||
COPY --from=tailwind /src/public/output.css ./public/
|
||||
COPY --from=node_builder /src/public /src/public
|
||||
COPY --from=node_builder /src/public/upload_obfuscated.js /src/public/upload.js
|
||||
COPY --from=node_builder /src/public/validatePassword_obfuscated.js /src/public/validatePassword.js
|
||||
|
||||
RUN apk update && apk upgrade && apk add --no-cache ca-certificates
|
||||
RUN update-ca-certificates
|
||||
RUN go install github.com/a-h/templ/cmd/templ@$(go list -m -f '{{ .Version }}' github.com/a-h/templ)
|
||||
RUN templ generate
|
||||
RUN go build -o ./tmp/main
|
||||
RUN rm /src/public/validatePassword_obfuscated.js /src/public/upload_obfuscated.js
|
||||
|
||||
FROM scratch
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
COPY --from=go_builder /src /src
|
||||
COPY --from=go_builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=go_builder /src/schema.sql /src
|
||||
COPY --from=go_builder /src/public /src/public
|
||||
COPY --from=go_builder /src/tmp/main /src
|
||||
|
||||
ENTRYPOINT ["./tmp/main"]
|
||||
ENTRYPOINT ["./main"]
|
||||
|
@ -3,7 +3,6 @@ package db
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/types/models"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/postgres"
|
||||
@ -13,7 +12,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
var DB Database
|
||||
|
||||
type mySQLdb struct {
|
||||
@ -51,7 +49,28 @@ type Database interface {
|
||||
|
||||
func NewMYSQLdb(username, password, host, port, dbName string) Database {
|
||||
var err error
|
||||
connection := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", username, password, host, port, dbName)
|
||||
var count int64
|
||||
|
||||
connection := fmt.Sprintf("%s:%s@tcp(%s:%s)/", username, password, host, port)
|
||||
initDB, err := gorm.Open(mysql.New(mysql.Config{
|
||||
DSN: connection,
|
||||
DefaultStringSize: 256,
|
||||
DisableDatetimePrecision: true,
|
||||
DontSupportRenameIndex: true,
|
||||
DontSupportRenameColumn: true,
|
||||
SkipInitializeWithVersion: false,
|
||||
}), &gorm.Config{
|
||||
Logger: gormLogger.Default.LogMode(gormLogger.Silent),
|
||||
})
|
||||
|
||||
initDB.Raw("SELECT count(*) FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = ?", dbName).Scan(&count)
|
||||
if count <= 0 {
|
||||
if err := initDB.Exec("CREATE DATABASE IF NOT EXISTS " + dbName).Error; err != nil {
|
||||
panic("Error creating database: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
connection = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", username, password, host, port, dbName)
|
||||
DB, err := gorm.Open(mysql.New(mysql.Config{
|
||||
DSN: connection,
|
||||
DefaultStringSize: 256,
|
||||
@ -83,7 +102,6 @@ func NewMYSQLdb(username, password, host, port, dbName string) Database {
|
||||
panic("Error executing query: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return &mySQLdb{DB}
|
||||
}
|
||||
|
||||
|
46
docker-compose.yaml
Normal file
46
docker-compose.yaml
Normal file
@ -0,0 +1,46 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
mysql-filekeeper:
|
||||
image: mysql:latest
|
||||
container_name: mysql-filekeeper
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: VerySecretPassword
|
||||
volumes:
|
||||
- /opt/mysql:/var/lib/mysql
|
||||
networks:
|
||||
- filekeeper
|
||||
|
||||
filekeeper:
|
||||
image: fossyy/filekeeper:latest
|
||||
container_name: filekeeper
|
||||
environment:
|
||||
SERVER_HOST: 0.0.0.0
|
||||
SERVER_PORT: 8000
|
||||
DOMAIN: filekeeper.fossy.my.id
|
||||
CORS_PROTO: https
|
||||
CORS_LIST: filekeeper.fossy.my.id:443,fossy.my.id:443
|
||||
CORS_METHODS: POST,GET
|
||||
DB_HOST: mysql-filekeeper
|
||||
DB_PORT: 3306
|
||||
DB_USERNAME: root
|
||||
DB_PASSWORD: VerySecretPassword
|
||||
DB_NAME: filekeeper
|
||||
SMTP_HOST: mail.example.com
|
||||
SMTP_PORT: 25
|
||||
SMTP_USER: no-reply@example.com
|
||||
SMTP_PASSWORD: VerySecretPassword
|
||||
SESSION_NAME: Session
|
||||
SESSION_MAX_AGE: 604800
|
||||
volumes:
|
||||
- /opt/filekeeper/uploads:/src/uploads
|
||||
networks:
|
||||
- filekeeper
|
||||
depends_on:
|
||||
- mysql-filekeeper
|
||||
restart: on-failure
|
||||
ports:
|
||||
- "8000:8000"
|
||||
|
||||
networks:
|
||||
filekeeper:
|
@ -105,7 +105,6 @@ func ConvertFileSize(byte int) string {
|
||||
func Getenv(key string) string {
|
||||
env.mu.Lock()
|
||||
defer env.mu.Unlock()
|
||||
|
||||
if val, ok := env.value[key]; ok {
|
||||
return val
|
||||
}
|
||||
|
Reference in New Issue
Block a user