Skip to content

Commit

Permalink
GitButler Integration Commit
Browse files Browse the repository at this point in the history
This is an integration commit for the virtual branches that GitButler is tracking.

Due to GitButler managing multiple virtual branches, you cannot switch back and
forth between git branches and virtual branches easily. 

If you switch to another branch, GitButler will need to be reinitialized.
If you commit on this branch, GitButler will throw it away.

Here are the branches that are currently applied:
 - next (refs/gitbutler/next)
   branch head: bdc646c
For more information about what we're doing here, check out our docs:
https://docs.gitbutler.com/features/virtual-branches/integration-branch
  • Loading branch information
gitbutler-client committed May 23, 2024
1 parent a794a88 commit 6469011
Show file tree
Hide file tree
Showing 17 changed files with 206 additions and 119 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,32 @@ jobs:
- name: Build binaries for all platforms
run: .github/workflows/release.sh

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Test docker
run: |
set -ex
docker build -t test --target test --build-arg LDFLAGS="${{ env.LDFLAGS }}" ..
docker run --rm --name test -p 8080:80 test &
go run . hurl
docker stop test
working-directory: ./test

- name: Build docker and push
uses: docker/build-push-action@v5
with:
context: .
push: true
build-args: |
LDFLAGS=${{ env.LDFLAGS }}
tags: |
infogulch/xtemplate:${{ env.VERSION }}
${{ startsWith(github.ref, 'refs/tags/v') && 'infogulch/xtemplate:latest' || null }}
- uses: actions/upload-artifact@v4
with:
name: xtemplate-dist
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ GITVER="$(git describe --exact-match --tags --match="v*" 2> /dev/null || git rev
VERSION="$(go list -f '{{.Version}}' -m github.com/infogulch/xtemplate@$GITVER)"
LDFLAGS="-X 'github.com/infogulch/xtemplate/app.version=$VERSION'"

echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "LDFLAGS=$LDFLAGS" >> $GITHUB_ENV

GOOS=linux GOARCH=amd64 go build -ldflags="$LDFLAGS" -buildmode exe -o ./dist/xtemplate-amd64-linux/xtemplate ./cmd
GOOS=darwin GOARCH=amd64 go build -ldflags="$LDFLAGS" -buildmode exe -o ./dist/xtemplate-amd64-darwin/xtemplate ./cmd
GOOS=windows GOARCH=amd64 go build -ldflags="$LDFLAGS" -buildmode exe -o ./dist/xtemplate-amd64-windows/xtemplate.exe ./cmd

docker build -t "xtemplate:$VERSION" --build-arg LDFLAGS="$LDFLAGS" .

# Get version from image to spot check that the binary can run:
echo "Build docker image with version: $(docker run -i --rm "xtemplate:$VERSION" --version)"

cd dist

printf '%s\n' * | while read D; do
Expand Down
65 changes: 43 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
FROM golang:1-alpine AS builder
FROM golang:1-alpine AS deps

RUN apk add --no-cache build-base

WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download -x

###

FROM deps AS build

ARG LDFLAGS

COPY app ./app/
COPY cmd ./cmd/
COPY providers ./providers/
COPY *.go ./
RUN CGO_ENABLED=1 \
GOFLAGS='-tags="sqlite_json"' \
GOOS=linux \
GOARCH=amd64 \
go build -x -ldflags="${LDFLAGS} -X 'github.com/infogulch/xtemplate/app.defaultWatchTemplates=false' -X 'github.com/infogulch/xtemplate/app.defaultListenAddress=0.0.0.0:80'" -o /build/xtemplate ./cmd

###

FROM alpine AS dist

ENV USER=appuser
ENV UID=10001
RUN adduser \
Expand All @@ -14,33 +36,32 @@ RUN adduser \
--no-create-home \
--uid "${UID}" \
"${USER}"
WORKDIR /app
USER $USER:$USER
EXPOSE 80

WORKDIR /build
COPY go.mod go.sum /build/
RUN go mod download
COPY --from=build /build/xtemplate /app/xtemplate

COPY . /build/
RUN CGO_ENABLED=1 \
GOFLAGS='-tags="sqlite_json"' \
GOOS=linux \
GOARCH=amd64 \
go build -ldflags="${LDFLAGS}" -o /dist/xtemplate ./cmd
RUN ldd /dist/xtemplate | tr -s [:blank:] '\n' | grep ^/ | xargs -I % install -D % /dist/%
RUN ln -s ld-musl-x86_64.so.1 /dist/lib/libc.musl-x86_64.so.1
ENTRYPOINT ["/app/xtemplate"]

###

FROM scratch
FROM dist AS test

COPY --from=builder /etc/passwd /etc/group /etc/
COPY --from=builder /dist/lib /lib/
COPY --from=builder /dist/xtemplate /app/xtemplate
COPY ./test/templates /app/templates/
COPY ./test/data /app/data/
COPY ./test/config.json /app/

WORKDIR /app
VOLUME /app/data
USER appuser:appuser
EXPOSE 80
USER root:root
RUN mkdir /app/dataw; chown $USER:$USER /app/dataw
USER $USER:$USER

ENTRYPOINT ["/app/xtemplate"]
VOLUME /app/dataw

RUN ["/app/xtemplate", "--version"]

CMD ["--loglevel", "-4", "-d", "DB:sql:sqlite3:file:./dataw/test.sqlite", "-d", "FS:fs:./data", "--config-file", "config.json"]

###

CMD ["--template-dir", "./templates", "--watch-templates", "false", "--listen", ":80"]
FROM dist as final
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ designs, otherwise they'll be in the way of the fundamentals:
<details><summary><strong>🔱 Add custom routes to handle any method and path pattern</strong></summary>
> Handle any [Go 1.22 ServeMux](servemux) pattern by **defining a template with
> Handle any [Go 1.22 ServeMux][servemux] pattern by **defining a template with
> that pattern as its name**. Path placeholders are available during template
> execution with the `.Req.PathValue` method.
>
Expand Down Expand Up @@ -365,15 +365,13 @@ additional features and enhancements. Here are the key things to keep in mind:
- You can define custom routes by defining a template with a special name in
your template files. For example, `{{define "GET /custom-route"}}...{{end}}`
will create a new route that handles GET requests to `/custom-route`. Names
also support path parameters as defined by [http.ServeMux](servemux).
also support path parameters as defined by [http.ServeMux][servemux].
- Template files can be invoked from within other templates using either their
full path relative to the template root or by using its defined template name.
- Templates are executed with a uniform context object, which provides access to
request data, database connections, and other useful dynamic functionality.
- Templates can also call functions set at startup.
[servemux]: https://pkg.go.dev/net/http#ServeMux
> [!note]
>
> Custom dot fields and functions are similar in that they both add
Expand Down Expand Up @@ -439,17 +437,17 @@ You can custom FuncMaps by configuring the `Config.FuncMaps` field.
* 📏 `xtemplate` includes funcs to render markdown, sanitize html, convert
values to human-readable forms, and to try to call a function to handle an
error within the template. See the free functions named [`FuncXYZ(...)` in
xtemplate's Go docs](funcgodoc) for details.
xtemplate's Go docs][funcgodoc] for details.
* 📏 Sprig publishes a library of useful template funcs that enable templates to
manipulate strings, integers, floating point numbers, and dates, as well as
perform encoding tasks, manipulate lists and dicts, converting types,
and manipulate file paths See [Sprig Function Documentation](sprig).
and manipulate file paths See [Sprig Function Documentation][sprig].
* 📏 Go's built in functions add logic and basic printing functionality.
See: [text/template#Functions](gofuncs).
See: [text/template#Functions][gofuncs].
[funcgodoc]: https://pkg.go.dev/github.com/infogulch/xtemplate#FuncHumanize
[sprig]: https://masterminds.github.io/sprig/
[gofuncs]: https://pkg.go.dev/text/template#hdr-Functions
[funcgodoc]: https://pkg.go.dev/github.com/infogulch/xtemplate#FuncHumanize
## 🏆 Users
Expand Down
12 changes: 8 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
type Args struct {
xtemplate.Config
Watch []string `json:"watch_dirs" arg:",separate"`
WatchTemplates bool `json:"watch_templates" default:"true"`
Listen string `json:"listen" arg:"-l" default:"0.0.0.0:8080"`
WatchTemplates bool `json:"watch_templates"`
Listen string `json:"listen" arg:"-l"`
LogLevel int `json:"log_level" default:"-2"`
Configs []string `json:"-" arg:"-c,--config,separate"`
ConfigFiles []string `json:"-" arg:"-f,--config-file,separate"`
Expand All @@ -29,13 +29,17 @@ func (Args) Version() string {
return version
}

var defaultWatchTemplates = "true"
var defaultListenAddress = "0.0.0.0:8080"
var defaultArgs = Args{WatchTemplates: defaultWatchTemplates == "true", Listen: defaultListenAddress}

// Main can be called from your func main() if you want your program to act like
// the default xtemplate cli, or use it as a reference for making your own.
// Provide configs to override the defaults like:
//
// app.Main(xtemplate.WithFooConfig())
func Main(overrides ...xtemplate.Option) {
var config Args
var config Args = defaultArgs
var log *slog.Logger

{
Expand All @@ -45,7 +49,7 @@ func Main(overrides ...xtemplate.Option) {
level := config.LogLevel
log = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.Level(level)}))

var jsonConfig Args
var jsonConfig Args = defaultArgs
var decoded bool
for _, name := range config.ConfigFiles {
func() {
Expand Down
11 changes: 7 additions & 4 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,16 @@ func (b *builder) addTemplateHandler(path_ string) error {
// strip the extension from the handled path
routePath := strings.TrimSuffix(path_, b.config.TemplateExtension)
// files named 'index' handle requests to the directory
if path.Base(routePath) == "index" {
routePath = path.Dir(routePath)
base := path.Base(routePath)
if base == "index" {
routePath = path.Dir(routePath) + "/"
}
if strings.HasSuffix(routePath, "/") {
routePath += "{$}"
if base == "index{$}" {
routePath = path.Dir(routePath) + "/{$}"
}
routePath = path.Clean(routePath)
pattern = "GET " + routePath
fmt.Printf("pattern: %s\n", pattern)
handler = bufferingTemplateHandler(b.Instance, tmpl)
} else if matches := routeMatcher.FindStringSubmatch(name); len(matches) == 3 {
method, path_ := matches[1], matches[2]
Expand Down
15 changes: 14 additions & 1 deletion funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,20 @@ func FuncTry(fn any, args ...any) (*result, error) {
}
fnv := reflect.ValueOf(fn)
if fnv.Kind() != reflect.Func {
return nil, fmt.Errorf("not a function")
if len(args) == 0 {
return nil, fmt.Errorf("not callable (no method name provided)")
}
methodName, ok := args[0].(string)
if !ok {
return nil, fmt.Errorf("not callable (non-string method name)")
}
method := fnv.MethodByName(methodName)
if method.IsValid() {
fnv = method
args = args[1:]
} else {
return nil, fmt.Errorf("not callable (method not found)")
}
}
n := fnv.Type().NumOut()
if n != 1 && n != 2 {
Expand Down
34 changes: 17 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,52 @@ require (
github.com/BurntSushi/toml v1.3.2
github.com/Masterminds/sprig/v3 v3.2.3
github.com/alecthomas/chroma/v2 v2.13.0
github.com/alexflint/go-arg v1.4.3
github.com/alexflint/go-arg v1.5.0
github.com/andybalholm/brotli v1.1.0
github.com/dustin/go-humanize v1.0.1
github.com/felixge/httpsnoop v1.0.4
github.com/google/uuid v1.6.0
github.com/infogulch/watch v0.2.0
github.com/klauspost/compress v1.17.7
github.com/klauspost/compress v1.17.8
github.com/mattn/go-sqlite3 v1.14.22
github.com/microcosm-cc/bluemonday v1.0.26
github.com/nats-io/nats-server/v2 v2.10.12
github.com/nats-io/nats.go v1.34.1
github.com/tdewolff/minify/v2 v2.20.19
github.com/nats-io/nats-server/v2 v2.10.15
github.com/nats-io/nats.go v1.35.0
github.com/tdewolff/minify/v2 v2.20.24
github.com/yuin/goldmark v1.7.1
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
gopkg.in/yaml.v3 v3.0.1
)

// Don't drink and drive, and don't change your repo's import path, kids.
// https://github.com/darccio/mergo/issues/244 🙄
replace github.com/imdario/mergo => github.com/imdario/mergo v0.3.16
// Pin mergo to v0.3.16
require github.com/imdario/mergo v0.3.16 // indirect

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/alexflint/go-scalar v1.1.0 // indirect
github.com/alexflint/go-scalar v1.2.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/nats-io/jwt/v2 v2.5.5 // indirect
github.com/nats-io/jwt/v2 v2.5.7 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/tdewolff/parse/v2 v2.7.12 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/tdewolff/parse/v2 v2.7.14 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/time v0.5.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
Loading

0 comments on commit 6469011

Please sign in to comment.