initial commit

This commit is contained in:
Djeeberjr 2023-09-05 16:44:53 +02:00
commit 93eea1fad0
9 changed files with 102 additions and 0 deletions

7
cookiecutter.json Normal file
View File

@ -0,0 +1,7 @@
{
"project_name": "Go Project",
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '-')}}",
"mod_name": "{{ cookiecutter.project_name.lower().replace(' ', '').replace('-', '')}}",
"docker_username": "djeeberjr",
"mod_base": "git.kapelle.org/niklas/{{cookiecutter.project_slug}}"
}

View File

@ -0,0 +1,9 @@
#!/usr/bin/env sh
set -e
git init
go mod init {{cookiecutter.mod_base}}
go mod tidy

View File

@ -0,0 +1 @@
.gitignore

View File

@ -0,0 +1 @@
/build

View File

@ -0,0 +1,22 @@
FROM --platform=$BUILDPLATFORM golang:1.21-alpine as build
ADD . /app
WORKDIR /app
ARG TARGETARCH
ARG TARGETOS
RUN apk add --no-cache make
RUN make build BUILD_ARCH="$TARGETARCH" BUILD_OS="$TARGETOS"
FROM --platform=$TARGETPLATFORM alpine:latest
RUN apk add --no-cache make ca-certificates
WORKDIR /data
COPY --from=build /app/build/{{cookiecutter.project_slug}} /app/{{cookiecutter.project_slug}}
EXPOSE 3000
VOLUME [ "/data" ]
CMD [ "/app/{{cookiecutter.project_slug}}" ]

View File

@ -0,0 +1,21 @@
BINARY = {{cookiecutter.project_slug}}
BUILD_DIR = build
BUILD_ARCH = $(shell go env GOARCH)
BUILD_OS = $(shell go env GOOS)
.PHONY: all
all: clean build
.PHONY:build
build: $(BUILD_DIR)/$(BINARY)
$(BUILD_DIR)/$(BINARY):
GOARCH=$(BUILD_ARCH) GOOS=$(BUILD_OS) go build -o $(BUILD_DIR)/$(BINARY) cmd/{{cookiecutter.project_slug}}.go
.PHONY:clean
clean:
rm -rf $(BUILD_DIR)
.PHONY: docker
docker:
docker buildx build --platform linux/arm64,linux/amd64,linux/arm/v7,linux/arm64/v8 -t djeeberjr/{{cookiecutter.project_slug}} . --push

View File

@ -0,0 +1,10 @@
# {{cookiecutter.project_name}}
## Build
`make build`
## Build and push docker image
`make docker`

View File

@ -0,0 +1,19 @@
package main
import (
{{cookiecutter.mod_name}} "{{cookiecutter.mod_base}}/internal"
"github.com/alexflint/go-arg"
)
type args struct {
Parameter string `arg:"--parameter,required,env:PARAMETER" placeholder:"PARAMETER"`
}
func main() {
var args args
arg.MustParse(&args)
{{cookiecutter.mod_name}}.Start({{cookiecutter.mod_name}}.Config{
Parameter: args.Parameter,
})
}

View File

@ -0,0 +1,12 @@
package {{cookiecutter.mod_name}}
import "fmt"
type Config struct {
Parameter string
}
func Start(config Config) {
fmt.Println("Starting {{cookiecutter.project_slug}}")
fmt.Println("Parameter: ", config.Parameter)
}