🎉 Initial commit
/ docker (push) Failing after 1m46s Details

First try to make a template repo with basic command project layout
This commit is contained in:
Maxim Lebedev 2024-05-01 04:24:17 +05:00
commit 4ef2495bf2
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
11 changed files with 248 additions and 0 deletions

18
.editorconfig Normal file
View File

@ -0,0 +1,18 @@
; https://editorconfig.org/
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.go]
indent_size = 8
indent_style = tab
[go.{mod,sum}]
indent_size = 4
indent_style = tab

10
.gitea/template Normal file
View File

@ -0,0 +1,10 @@
.editorconfig
.gitignore
build/Dockerfile
Makefile
go.{mod,sum}
.gitea/workflows/*.yaml
docs/*.md
text/*.txt
**/.gitkeep
**.go

View File

@ -0,0 +1,39 @@
---
on:
push:
branches:
- master
env:
DOCKER_REGISTRY: source.toby3d.me
jobs:
docker:
runs-on: ubuntu-latest
container:
image: catthehacker/ubuntu:act-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: https://gitea.com/actions/checkout@v3
- name: Set up QEMU
uses: https://gitea.com/docker/setup-qemu-action@v2
- name: Set up Docker BuildX
uses: https://gitea.com/docker/setup-buildx-action@v2
- name: Login to registry
uses: https://gitea.com/docker/login-action@v2
with:
password: ${{ secrets.DOCKER_TOKEN }}
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ gitea.repository_owner }}
- name: Build and push
uses: https://gitea.com/docker/build-push-action@v4
env:
ACTIONS_RUNTIME_TOKEN: "" # See https://gitea.com/gitea/act_runner/issues/119
with:
context: .
file: ./build/Dockerfile
push: true
tags: ${{ env.DOCKER_REGISTRY }}/${{ gitea.repository }}:${{ gitea.ref_name }}

22
.gitignore vendored Normal file
View File

@ -0,0 +1,22 @@
### Go ###
# 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

30
Makefile Normal file
View File

@ -0,0 +1,30 @@
#!/usr/bin/make -f
SHELL = /bin/sh
srcdir = .
GO ?= go
GOFLAGS ?= -buildvcs=true
CGO_ENABLED = 0
EXECUTABLE ?= ${REPO_NAME_LOWER}
DOCKER ?= docker
DOCKERFLAGS ?= --rm
.PHONY: all clean check container help
all: main.go # Build execution file for current environment
$(GO) build -v $(GOFLAGS) -o $(EXECUTABLE)
clean: ## Delete all files in the current directory that are normally created by building the program
$(GO) clean
check: ## Perform self-tests
$(GO) test -v -cover -failfast -short -shuffle=on $(GOFLAGS) $(srcdir)/...
container: build/Dockerfile ## Builds Docker container image
$(DOCKER) build $(DOCKERFLAGS) -f $(srcdir)/build/Dockerfile -t $REPO_LINK .
.PHONY: help
help: ## Display this help screen
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

26
build/Dockerfile Normal file
View File

@ -0,0 +1,26 @@
# syntax=docker/dockerfile:1
# docker build --rm -f build/Dockerfile -t $REPO_LINK .
# Build
FROM golang:alpine AS builder
WORKDIR /app
ENV GOFLAGS="-mod=vendor -buildvcs=true"
COPY . ./
RUN apk --no-cache add ca-certificates
RUN go build -o ./${REPO_NAME_LOWER}
# Run
FROM scratch
WORKDIR /
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /app/${REPO_NAME_LOWER} /${REPO_NAME_LOWER}
EXPOSE 3000
ENTRYPOINT ["/${REPO_NAME_LOWER}"]

2
docs/README.en.md Normal file
View File

@ -0,0 +1,2 @@
# $REPO_NAME_LOWER
> $REPO_DESCRIPTION

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module $REPO_LINK
go 1.22.2
require github.com/caarlos0/env/v10 v10.0.0

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/caarlos0/env/v10 v10.0.0 h1:yIHUBZGsyqCnpTkbjk8asUlx6RFhhEs+h7TOBdgdzXA=
github.com/caarlos0/env/v10 v10.0.0/go.mod h1:ZfulV76NvVPw3tm591U4SwL3Xx9ldzBP9aGxzeN7G18=

View File

@ -0,0 +1,5 @@
package domain
type Config struct {
BIND string `env:"BIND" envDefault:":3000"`
}

89
main.go Normal file
View File

@ -0,0 +1,89 @@
//go:generate go install github.com/valyala/quicktemplate/qtc@master
//go:generate qtc -dir=web/template
//go:generate go install golang.org/x/text/cmd/gotext@master
//go:generate gotext -srclang=en update -lang=en,ru -out=locales_gen.go
package main
import (
"$REPO_LINK/internal/domain"
"flag"
"log"
"os"
"os/signal"
"runtime"
"runtime/pprof"
"syscall"
"github.com/caarlos0/env/v10"
)
var (
cpuProfilePath string
memProfilePath string
)
var (
config *domain.Config = new(domain.Config)
logger *log.Logger = log.New(os.Stdout, "$REPO_NAME_LOWER\t", log.LstdFlags)
)
func init() {
flag.StringVar(&cpuProfilePath, "cpuprofile", "", "set path to saving CPU memory profile")
flag.StringVar(&memProfilePath, "memprofile", "", "set path to saving pprof memory profile")
flag.Parse()
if err := env.ParseWithOptions(config, env.Options{
Environment: nil,
FuncMap: nil,
OnSet: nil,
Prefix: "${REPO_NAME_UPPER}_",
RequiredIfNoDef: false,
TagName: "env",
UseFieldNameByDefault: true,
}); err != nil {
logger.Fatalln(err)
}
}
func main() {
done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
if cpuProfilePath != "" {
cpuProfile, err := os.Create(cpuProfilePath)
if err != nil {
logger.Fatalln("could not create CPU profile:", err)
}
defer cpuProfile.Close()
if err = pprof.StartCPUProfile(cpuProfile); err != nil {
logger.Fatalln("could not write CPU profile:", err)
}
defer pprof.StopCPUProfile()
}
go func() {
// TODO(toby3d): do something blocking here.
logger.Println("$REPO_NAME_LOWER binded to", config.BIND)
}()
<-done
// TODO(toby3d): graceful shutdown here.
if memProfilePath == "" {
return
}
memProfile, err := os.Create(memProfilePath)
if err != nil {
logger.Fatalln("could not create memory profile:", err)
}
defer memProfile.Close()
runtime.GC() // NOTE(toby3d): get up-to-date statistics
if err = pprof.WriteHeapProfile(memProfile); err != nil {
logger.Fatalln("could not write memory profile:", err)
}
}