Skip to content

Commit

Permalink
ci: makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaBosak233 committed May 26, 2024
1 parent a0cee8f commit 28c42b8
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 146 deletions.
32 changes: 2 additions & 30 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,49 +1,21 @@
### Go template
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.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
sqlite.db
db.sqlite3
.idea
config.yml
logs
plugins
uploads
/media/
/assets/
/config/
/configs/*
/application.json
/signature.json
/platform.json
/k8s-config.yml
/ca/
/configs/
/db/
/build/
/captures/
test.go
dist
_PgsHub.exe
_Cloudsdale.exe
signature.json
config.json

__pycache__
/dist/
21 changes: 10 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
FROM golang:1.22-alpine as builder
FROM golang:latest AS backend

RUN apk add --no-cache git python3 py3-pip gcc musl-dev nodejs npm
COPY ./ /app

COPY ./ /app/backend
COPY ./client /app/frontend
WORKDIR /app

RUN make build

WORKDIR /app/backend
FROM node:20 AS frontend

RUN python3 scripts/buildtool.py build
RUN cp build/cloudsdale /go/bin/cloudsdale
COPY ./client /app

WORKDIR /app/frontend
WORKDIR /app

RUN npm install
RUN npm run build
RUN cp -r dist /go/dist

FROM alpine:3.14

COPY --from=builder /go/bin/cloudsdale /app/cloudsdale
COPY --from=builder /go/dist /app/dist
COPY --from=backend /app/build/cloudsdale /app/cloudsdale
COPY --from=frontend /app/dist /app/dist

WORKDIR /app

Expand Down
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
BINARY := cloudsdale
PACKAGE := github.com/elabosak233/cloudsdale

GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)

export TERM := xterm-256color
export CGO_ENABLED := 1

GIT_TAG := $(shell git describe --tags --always)
GIT_COMMIT := $(shell git rev-parse HEAD)
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)

LDFLAGS := -X $(PACKAGE)/internal/global.GitTag=$(GIT_TAG) -X $(PACKAGE)/internal/global.GitCommitID=$(GIT_COMMIT) -X $(PACKAGE)/internal/global.GitBranch=$(GIT_BRANCH)

.PHONY: all build run clean swag

all: build

clean:
@rm -rf ./build

swag:
@echo Generating swagger docs...
swag init -g ./cloudsdale.go -o ./api
@echo Swagger docs generated.

build: swag
@echo Building $(PACKAGE)...
@go build -ldflags "-linkmode external -w -s $(LDFLAGS)" -o ./build/$(BINARY)
@echo Build finished.

run: swag
@echo Running $(PACKAGE)...
go run -ldflags "$(LDFLAGS)" $(PACKAGE)
@echo Run finished.
26 changes: 26 additions & 0 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "3.0"
services:
core:
image: elabosak233/cloudsdale:main
restart: always
ports:
- "8888:8888"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "./configs:/app/configs"
- "./media:/app/media"
- "./logs:/app/logs"
depends_on:
- db

db:
image: postgres:alpine
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_USER: cloudsdale
POSTGRES_PASSWORD: cloudsdale
POSTGRES_DB: cloudsdale
volumes:
- "./db:/var/lib/postgresql/data"
6 changes: 3 additions & 3 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func init() {
data, _ := assets.ReadStaticFile("banner.txt")
banner := string(data)
fmt.Printf("\n%s\n", banner)
fmt.Printf("%s %s\n", color.InBold("Commit IDs:"), color.InBold(global.GitCommitID))
fmt.Printf("%s %s\n", color.InBold("Build At:"), color.InBold(global.BuildAt))
fmt.Printf("%s %s\n\n", color.InBold("Issues:"), color.InBold("https://github.com/elabosak233/Cloudsdale/issues"))
fmt.Printf("%s %s\n", color.InBold("Git Commit:"), color.InBold(global.GitCommitID))
fmt.Printf("%s %s\n", color.InBold("Issues:"), color.InBold("https://github.com/elabosak233/Cloudsdale/issues"))
fmt.Printf("%s %s\n\n", color.InBold("License:"), color.InBold("GNU GENERAL PUBLIC LICENSE Version 3"))
}

func Run() {
Expand Down
6 changes: 3 additions & 3 deletions internal/extension/config/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ type ApplicationCfg struct {
Dbname string `yaml:"dbname" json:"dbname" mapstructure:"dbname"`
Sslmode string `yaml:"sslmode" json:"sslmode" mapstructure:"sslmode"`
} `yaml:"postgres" json:"postgres" mapstructure:"postgres"`
SQLite3 struct {
SQLite struct {
Filename string `yaml:"filename" json:"filename" mapstructure:"filename"`
} `yaml:"sqlite3" json:"sqlite3" mapstructure:"sqlite3"`
} `yaml:"sqlite" json:"sqlite" mapstructure:"sqlite"`
MySQL struct {
Host string `yaml:"host" json:"host" mapstructure:"host"`
Port int `yaml:"port" json:"port" mapstructure:"port"`
Expand Down Expand Up @@ -100,7 +100,7 @@ func AppCfg() *ApplicationCfg {

func InitApplicationCfg() {
v1 = viper.New()
configFile := path.Join("./application.json")
configFile := path.Join("configs", "application.json")
v1.SetConfigType("json")
v1.SetConfigFile(configFile)
if _, err := os.Stat(configFile); err != nil {
Expand Down
10 changes: 9 additions & 1 deletion internal/extension/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package config

import "github.com/google/uuid"
import (
"github.com/google/uuid"
"os"
)

var (
jwtSecretKey string
Expand All @@ -11,6 +14,11 @@ func JwtSecretKey() string {
}

func InitConfig() {
configPath := "configs"
if _, err := os.Stat(configPath); os.IsNotExist(err) {
_ = os.Mkdir(configPath, os.ModePerm)
}

InitApplicationCfg()
InitPlatformCfg()
InitSignatureCfg()
Expand Down
2 changes: 1 addition & 1 deletion internal/extension/config/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func PltCfg() *PlatformCfg {

func InitPlatformCfg() {
v2 = viper.New()
configFile := path.Join("./platform.json")
configFile := path.Join("configs", "platform.json")
v2.SetConfigType("json")
v2.SetConfigFile(configFile)
if _, err := os.Stat(configFile); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/extension/config/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func SigCfg() *SignatureCfg {

func InitSignatureCfg() {
v3 = viper.New()
configFile := path.Join("./signature.json")
configFile := path.Join("configs", "signature.json")
v3.SetConfigType("json")
v3.SetConfigFile(configFile)

Expand Down
4 changes: 2 additions & 2 deletions internal/extension/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func initDatabaseEngine() {
config.AppCfg().Db.MySQL.Dbname,
)
db, err = gorm.Open(mysql.Open(dbInfo), &gorm.Config{})
case "sqlite3":
dbInfo = config.AppCfg().Db.SQLite3.Filename
case "sqlite":
dbInfo = config.AppCfg().Db.SQLite.Filename
db, err = gorm.Open(sqlite.Open(dbInfo), &gorm.Config{})
}
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions internal/extension/files/configs/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"expiration": 180
},
"paths": {
"media": "./media",
"assets": "./assets",
"frontend": "./dist"
"media": "/media",
"assets": "/assets",
"frontend": "/dist"
},
"host": "0.0.0.0",
"port": 8888
Expand All @@ -27,7 +27,7 @@
},
"traffic_capture": {
"enabled": false,
"path": "./captures"
"path": "/captures"
}
},
"db": {
Expand All @@ -47,8 +47,8 @@
"password": "cloudsdale",
"port": 3306
},
"sqlite3": {
"filename": "./db.sqlite3"
"sqlite": {
"filename": "/db/cloudsdale.sqlite"
}
},
"email": {
Expand Down
3 changes: 2 additions & 1 deletion internal/global/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package global
// Need to be injected by -ldflags
var (
GitCommitID = "N/A"
BuildAt = "N/A"
GitBranch = "N/A"
GitTag = "N/A"
)
87 changes: 0 additions & 87 deletions scripts/buildtool.py

This file was deleted.

0 comments on commit 28c42b8

Please sign in to comment.