Skip to content

Commit

Permalink
Merge pull request #11 from tech-thinker/10-arm-support-required-for-…
Browse files Browse the repository at this point in the history
…docker-based-development

arm support added for docker based development
  • Loading branch information
mrasif authored Dec 3, 2024
2 parents e69d9be + 68b9c66 commit f5d3747
Show file tree
Hide file tree
Showing 25 changed files with 219 additions and 216 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ build:
go build -ldflags="$(LDFLAGS)" -o gozen

dist:
cp man/gozen.1 man/gozen.old
sed -e "s|BUILDDATE|$(BUILDDATE)|g" -e "s|VERSION|$(VERSION)|g" man/gozen.old > man/gozen.1

GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o build/gozen-linux-amd64
cp build/gozen-linux-amd64 build/gozen
tar -zcvf build/gozen-linux-amd64.tar.gz build/gozen man/gozen.1
Expand Down Expand Up @@ -62,6 +65,9 @@ dist:
cd build && sha256sum * >> checksum-sha256sum.txt
cd build && md5sum * >> checksum-md5sum.txt

# Cleaning
mv man/gozen.old man/gozen.1

clean:
rm -rf gozen*
rm -rf build
24 changes: 11 additions & 13 deletions cmd/create_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ type appCmd struct {
}

func (cmd *appCmd) CreateApp() error {
workDir := constants.CURRENT_WORKING_DIRECTORY
if len(cmd.project.WorkingDir) > 1 {
workDir = cmd.project.WorkingDir
}
workDir := constants.CURRENT_WORKING_DIRECTORY
if len(cmd.project.WorkingDir) > 1 {
workDir = cmd.project.WorkingDir
}
appPath := fmt.Sprintf(`%s/%s`, workDir, cmd.project.AppName)
fmt.Println("Project created at location: " + appPath)
utils.CreateDirectory(appPath)
Expand All @@ -36,15 +36,13 @@ func (cmd *appCmd) CreateApp() error {
cmd.helper.Write("templates/env.sample.tpl", appPath+"/.env.sample", cmd.project)
cmd.helper.Write("templates/env.sample.tpl", appPath+"/docker/.env", cmd.project)
cmd.helper.Write("templates/env.sample.tpl", appPath+"/docker/.env.sample", cmd.project)
cmd.helper.Write("templates/docker/Dockerfile.debug", appPath+"/docker/Dockerfile.debug", cmd.project)
cmd.helper.Write("templates/docker/Dockerfile.dev", appPath+"/docker/Dockerfile.dev", cmd.project)
cmd.helper.Write("templates/docker/Dockerfile.prod", appPath+"/docker/Dockerfile.prod", cmd.project)
cmd.helper.Write("templates/docker/docker-compose-debug.yml", appPath+"/docker/docker-compose-debug.yml", cmd.project)
cmd.helper.Write("templates/docker/docker-compose.yml", appPath+"/docker/docker-compose.yml", cmd.project)
cmd.helper.Write("templates/docker/entrypoint-debug.sh", appPath+"/docker/entrypoint-debug.sh", cmd.project)
cmd.helper.Write("templates/docker/entrypoint-dev.sh", appPath+"/docker/entrypoint-dev.sh", cmd.project)
cmd.helper.Write("templates/docker/modd-debug.conf", appPath+"/docker/modd-debug.conf", cmd.project)
cmd.helper.Write("templates/docker/modd-dev.conf", appPath+"/docker/modd-dev.conf", cmd.project)
cmd.helper.Write("templates/docker/Dockerfile.debug", appPath+"/docker/Dockerfile.debug", cmd.project)
cmd.helper.Write("templates/docker/Dockerfile.dev", appPath+"/docker/Dockerfile.dev", cmd.project)
cmd.helper.Write("templates/docker/Dockerfile.prod", appPath+"/docker/Dockerfile.prod", cmd.project)
cmd.helper.Write("templates/docker/docker-compose-debug.yml", appPath+"/docker/docker-compose-debug.yml", cmd.project)
cmd.helper.Write("templates/docker/docker-compose.yml", appPath+"/docker/docker-compose.yml", cmd.project)
cmd.helper.Write("templates/docker/modd-debug.conf", appPath+"/docker/modd-debug.conf", cmd.project)
cmd.helper.Write("templates/docker/modd-dev.conf", appPath+"/docker/modd-dev.conf", cmd.project)

cmd.helper.Write("templates/gitignore.tpl", appPath+"/.gitignore", cmd.project)
cmd.helper.Write("templates/Makefile.tpl", appPath+"/Makefile", cmd.project)
Expand Down
68 changes: 34 additions & 34 deletions cmd/helper/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,57 @@ import (
)

type CommonHelper interface {
Write(templatePath string, outputPath string, data interface{}) error
ExecShell(command string, args ...string) ([]string, error)
ExecShellRaw(command string, args ...string) ([]byte, error)
Write(templatePath string, outputPath string, data interface{}) error
ExecShell(command string, args ...string) ([]string, error)
ExecShellRaw(command string, args ...string) ([]byte, error)
}

type commonHelper struct {
templatesFS embed.FS
templatesFS embed.FS
}

// Write: generate code and write to file
func (helper *commonHelper) Write(templatePath string, outputPath string, data interface{}) error {
baseDir := filepath.Dir(outputPath)
err := utils.CreateDirectory(baseDir)
if err != nil {
return err
}
tpl, err := utils.GenerateCode(helper.templatesFS, templatePath, data)
if err != nil {
return err
}
return utils.WriteFile(outputPath, tpl)
baseDir := filepath.Dir(outputPath)
err := utils.CreateDirectory(baseDir)
if err != nil {
return err
}
tpl, err := utils.GenerateCode(helper.templatesFS, templatePath, data)
if err != nil {
return err
}
return utils.WriteFile(outputPath, tpl)
}

// ExecShell: execute shell command and return output as string slice
func (helper *commonHelper) ExecShell(command string, args ...string) ([]string, error) {
fmt.Printf(`%s %+v\n`, command, args)
cmd := exec.Command(command, args...)
output, err := cmd.Output()
if err != nil {
fmt.Println("Error executing command:", err)
return nil, err
}
lines := strings.Split(strings.TrimSpace(string(output)), "\n")
return lines, nil
fmt.Printf(`%s %+v\n`, command, args)
cmd := exec.Command(command, args...)
output, err := cmd.Output()
if err != nil {
fmt.Println("Error executing command:", err)
return nil, err
}
lines := strings.Split(strings.TrimSpace(string(output)), "\n")
return lines, nil
}

// ExecShellRaw: execute shell command and return output as byte array
func (helper *commonHelper) ExecShellRaw(command string, args ...string) ([]byte, error) {
fmt.Printf(`%s %+v\n`, command, args)
cmd := exec.Command(command, args...)
output, err := cmd.Output()
if err != nil {
fmt.Println("Error executing command:", err)
return nil, err
}
return output, nil
fmt.Printf(`%s %+v\n`, command, args)
cmd := exec.Command(command, args...)
output, err := cmd.Output()
if err != nil {
fmt.Println("Error executing command:", err)
return nil, err
}
return output, nil
}

// NewCommonHelper returns a new CommonHelper
func NewCommonHelper(tpl embed.FS) CommonHelper {
return &commonHelper{
templatesFS: tpl,
}
return &commonHelper{
templatesFS: tpl,
}
}
2 changes: 1 addition & 1 deletion constants/app.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package constants

const CURRENT_WORKING_DIRECTORY="."
const CURRENT_WORKING_DIRECTORY = "."
22 changes: 11 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
)

var (
AppVersion = "v0.0.0"
CommitHash = "unknown"
BuildDate = "unknown"
AppVersion = "v0.0.0"
CommitHash = "unknown"
BuildDate = "unknown"
)

//go:embed templates/*
Expand All @@ -31,7 +31,7 @@ func main() {

clientApp := cli.NewApp()
clientApp.Name = "gozen"
clientApp.Version = AppVersion
clientApp.Version = AppVersion
clientApp.Commands = []*cli.Command{
{
Name: "create",
Expand Down Expand Up @@ -64,16 +64,16 @@ func main() {
AppName: ctx.Args().Get(0),
PackageName: packageName,
Driver: driver,
WorkingDir: outputDir,
WorkingDir: outputDir,
}

err := project.Validate()
if err != nil {
fmt.Println(err)
return nil
}
err := project.Validate()
if err != nil {
fmt.Println(err)
return nil
}

project.AutoFixes()
project.AutoFixes()

app := cmd.NewAppCmd(project, helper)

Expand Down
2 changes: 1 addition & 1 deletion man/gozen.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH GOZEN 1 "September 25, 2024" "Version 0.1.2" "User Commands"
.TH GOZEN 1 "BUILDDATE" "Version VERSION" "User Commands"
.SH NAME
gozen \- is a simplified golang MVC framework to generate projects and components.
.SH SYNOPSIS
Expand Down
24 changes: 12 additions & 12 deletions models/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ type Project struct {
AppName string `json:"app_name"`
PackageName string `json:"package_name"`
Driver string `json:"driver"`
WorkingDir string `json:"-"`
WorkingDir string `json:"-"`
}

func (p Project) Validate() error {
if len(p.PackageName) == 0 {
return errors.New("Please provide package name.")
}
return nil
if len(p.PackageName) == 0 {
return errors.New("Please provide package name.")
}
return nil
}

func (p *Project) AutoFixes() {
if len(p.AppName) == 0 {
p.AppName = p.PackageName[strings.LastIndex(p.PackageName, "/")+1:]
}
if len(p.AppName) == 0 {
p.AppName = p.PackageName[strings.LastIndex(p.PackageName, "/")+1:]
}
}

func (p Project) ToJSON() string {
Expand Down Expand Up @@ -58,10 +58,10 @@ func (p *Project) LoadFromJsonFile() error {
}

func (p Project) WriteToJsonFile() error {
workDir := constants.CURRENT_WORKING_DIRECTORY
if len(p.WorkingDir) > 1 {
workDir = p.WorkingDir
}
workDir := constants.CURRENT_WORKING_DIRECTORY
if len(p.WorkingDir) > 1 {
workDir = p.WorkingDir
}

filename := fmt.Sprintf(`%s/%s/gozen.json`, workDir, p.AppName)
file, err := os.Create(filename)
Expand Down
2 changes: 2 additions & 0 deletions templates/app/controllers/health.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ func (c *healthController) Ping(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"success": false,
"message": err.Error(),
"heart_beat": 0,
})
return
}
ctx.JSON(http.StatusOK, gin.H{
"success": res.Success,
"message": res.Message,
"heart_beat": res.HeartBeat,
})
}

Expand Down
40 changes: 20 additions & 20 deletions templates/config/config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ type Configuration interface {
Version() string
AppName() string
APIPort() string
DbDriver() string
DbDriver() string
DbHost() string
DbPort() string
DbUser() string
Expand All @@ -19,12 +19,12 @@ type configuration struct {
appName string
apiPort string
db_driver string
db_host string
db_port string
db_user string
db_pass string
db_name string
db_driver string
db_host string
db_port string
db_user string
db_pass string
db_name string
}

// Version returns version
Expand All @@ -44,32 +44,32 @@ func (cfg *configuration) APIPort() string {

// DbDriver returns database driver
func (config *configuration) DbDriver() string {
return config.db_driver
return config.db_driver
}

// DbHost returns database host
func (config *configuration) DbHost() string {
return config.db_host
return config.db_host
}

// DbPort returns database port
func (config *configuration) DbPort() string {
return config.db_port
return config.db_port
}

// DbUser returns database user
func (config *configuration) DbUser() string {
return config.db_user
return config.db_user
}

// DbPass returns database password
func (config *configuration) DbPass() string {
return config.db_pass
return config.db_pass
}

// DbName returns database name
func (config *configuration) DbName() string {
return config.db_name
return config.db_name
}

func Init(
Expand All @@ -82,11 +82,11 @@ func Init(
config.version = env.GetString("version")
config.apiPort = env.GetString("app_name")
config.apiPort = env.GetString("api_port")
config.db_driver = env.GetString("db_driver")
config.db_host = env.GetString("db_host")
config.db_port = env.GetString("db_port")
config.db_user = env.GetString("db_user")
config.db_pass = env.GetString("db_pass")
config.db_name = env.GetString("db_name")
config.db_driver = env.GetString("db_driver")
config.db_host = env.GetString("db_host")
config.db_port = env.GetString("db_port")
config.db_user = env.GetString("db_user")
config.db_pass = env.GetString("db_pass")
config.db_name = env.GetString("db_name")
return config
}
1 change: 0 additions & 1 deletion templates/constants/app.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ const (
)

// TODO: Add constants here.

33 changes: 28 additions & 5 deletions templates/docker/Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,35 @@ RUN apt-get update && \
curl \
gnupg-agent

RUN curl -sSL https://packagecloud.io/golang-migrate/migrate/gpgkey | apt-key add -
RUN echo "deb https://packagecloud.io/golang-migrate/migrate/ubuntu/ bionic main" > /etc/apt/sources.list.d/migrate.list
RUN apt-get update && \
apt-get install -y migrate
RUN apt-get update

# Install modd based on arch
RUN set -x && \
arch=$(dpkg --print-architecture) && \
case "$arch" in \
amd64) file="modd-0.8-linux64.tgz" ;; \
armhf|armel|arm64) file="modd-0.8-linuxARM.tgz" ;; \
i386) file="modd-0.8-linux32.tgz" ;; \
*) echo "Unsupported architecture: $arch" && exit 1 ;; \
esac && \
curl -sL "https://github.com/cortesi/modd/releases/download/v0.8/$file" -o modd.tgz && \
tar -xf modd.tgz && \
cp modd-0.8-*/modd /usr/bin/ && \
chmod +x /usr/bin/modd && rm -rf modd.tgz modd-0.8-*

# Install migrate
RUN set -x && \
arch=$(dpkg --print-architecture) && \
case "$arch" in \
amd64) file="migrate.linux-amd64.deb" ;; \
arm64) file="migrate.linux-arm64.deb" ;; \
armhf|armel) file="migrate.linux-armv7.deb" ;; \
i386) file="migrate.linux-386.deb" ;; \
*) echo "Unsupported architecture: $arch" && exit 1 ;; \
esac && \
curl -sL "https://github.com/golang-migrate/migrate/releases/download/v4.18.1/$file" -o migrate.deb && \
dpkg -i migrate.deb && rm migrate.deb

WORKDIR /app

ENTRYPOINT ["bash", "docker/entrypoint-dev.sh"]
ENTRYPOINT ["modd", "-f", "./docker/modd-debug.conf"]
Loading

0 comments on commit f5d3747

Please sign in to comment.