Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

fix(render): Windows compatibility for Auto rendering #1926

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 25 additions & 41 deletions Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,41 @@ FROM golang:latest

EXPOSE 3000

ENV BP=$GOPATH/src/github.com/gobuffalo/buffalo
ENV GOPROXY=https://proxy.golang.org
ENV GO111MODULE=ON

RUN go version

RUN curl -sL https://deb.nodesource.com/setup_10.x | bash \
&& sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' \
&& wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | apt-key add - \
&& apt-get update \
&& apt-get install -y -q build-essential nodejs sqlite3 libsqlite3-dev postgresql postgresql-contrib libpq-dev vim \
&& rm -rf /var/lib/apt/lists/*

RUN node -v
RUN npm -v

RUN service postgresql start && \
RUN apt-get update \
&& apt-get install -y -q build-essential sqlite3 libsqlite3-dev postgresql libpq-dev vim

# Installing Node 12
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash
RUN apt-get update && apt-get install nodejs

# Installing Postgres
RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' \
&& wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | apt-key add - \
&& apt-get update \
&& apt-get install -y -q postgresql postgresql-contrib libpq-dev\
&& rm -rf /var/lib/apt/lists/* \
&& service postgresql start && \
# Setting up password for postgres
su -c "psql -c \"ALTER USER postgres WITH PASSWORD 'postgres';\"" - postgres

RUN go get -tags sqlite -v -u github.com/gobuffalo/pop \
&& go get -tags sqlite -v -u github.com/gobuffalo/packr/v2/packr2 \
&& go get -tags sqlite -v -u github.com/gobuffalo/buffalo-pop \
&& rm -rf $GOPATH/src && mkdir -p $BP

# Install golangci
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.21.0

WORKDIR $BP

ADD go.mod .
ADD go.sum .

# preps the module cache for those using modules in their images
ENV GO111MODULE=on
RUN go mod tidy -v

# Installing yarn
RUN npm install -g --no-progress yarn \
&& yarn config set yarn-offline-mirror /npm-packages-offline-cache \
&& yarn config set yarn-offline-mirror-pruning true
&& yarn config set yarn-offline-mirror /npm-packages-offline-cache \
&& yarn config set yarn-offline-mirror-pruning true

COPY . .
# Install golangci
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0

RUN packr2 && go install -v -tags sqlite ./buffalo
# Pulling docker binary from releases
RUN wget https://github.com/gobuffalo/buffalo/releases/download/v0.16.1/buffalo_0.16.1_Linux_x86_64.tar.gz \
&& tar -xzf buffalo_0.16.1_Linux_x86_64.tar.gz \
&& mv buffalo $(go env GOPATH)/bin/buffalo

RUN buffalo version

RUN mkdir -p $GOPATH/src/github.com/markbates
WORKDIR $GOPATH/src/github.com/markbates

RUN buffalo new coke

RUN rm -rf coke

ENV GO111MODULE=off
WORKDIR $GOPATH/src
45 changes: 15 additions & 30 deletions Dockerfile.slim.build
Original file line number Diff line number Diff line change
@@ -1,43 +1,28 @@
FROM golang:alpine
EXPOSE 3000

ENV GOPROXY=https://proxy.golang.org
ENV GO111MODULE=ON

ENV BP=$GOPATH/src/github.com/gobuffalo/buffalo
ENV GOPROXY=https://proxy.golang.org

RUN apk add --no-cache --upgrade apk-tools \
&& apk add --no-cache bash curl openssl git build-base nodejs npm postgresql libpq postgresql-contrib sqlite sqlite-dev mysql-client vim

RUN go version && go get -v -u github.com/markbates/deplist/deplist


RUN go get -v -u github.com/gobuffalo/flect \
&& go get -v -u github.com/gobuffalo/makr \
&& go get -v -u github.com/gobuffalo/packr/v2 \
&& go get -v -u github.com/gobuffalo/tags \
&& go get -v -u github.com/gobuffalo/pop \
&& go get -v -u github.com/gobuffalo/x/... \
&& go get -v -u github.com/mattn/go-sqlite3 \
&& go get -v -u github.com/markbates/filetest \
&& go get -v -u github.com/markbates/grift \
&& go get -v -u github.com/markbates/refresh \
&& go get -v -u github.com/gobuffalo/httptest \
&& go get -v -u github.com/gorilla/sessions \
&& go get -v -u golang.org/x/vgo

RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.21.0
&& apk add --no-cache bash curl openssl git build-base nodejs npm sqlite sqlite-dev mysql-client vim postgresql libpq postgresql-contrib

# Installing linter
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh \
| sh -s -- -b $(go env GOPATH)/bin v1.24.0

# Installing Yarn
RUN npm i -g --no-progress yarn \
&& yarn config set yarn-offline-mirror /npm-packages-offline-cache \
&& yarn config set yarn-offline-mirror-pruning true


RUN rm -rfv $BP && mkdir -p $BP
WORKDIR $BP
&& yarn config set yarn-offline-mirror /npm-packages-offline-cache \
&& yarn config set yarn-offline-mirror-pruning true

COPY . .
ENV GO111MODULE=on
RUN make deps && make install
ENV GO111MODULE=
# Pulling docker binary from releases
RUN wget https://github.com/gobuffalo/buffalo/releases/download/v0.16.1/buffalo_0.16.1_Linux_x86_64.tar.gz \
&& tar -xzf buffalo_0.16.1_Linux_x86_64.tar.gz \
&& mv buffalo $(go env GOPATH)/bin/buffalo

RUN buffalo version

Expand Down
5 changes: 3 additions & 2 deletions buffalo/cmd/fix/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ var replace = map[string]string{
"github.com/gobuffalo/genny": "github.com/gobuffalo/genny/v2",
"github.com/gobuffalo/pop": "github.com/gobuffalo/pop/v5",
"github.com/gobuffalo/pop/nulls": "github.com/gobuffalo/nulls",
"github.com/gobuffalo/uuid": "github.com/gofrs/uuid/v3",
"github.com/gobuffalo/uuid": "github.com/gofrs/uuid",
"github.com/markbates/pop": "github.com/gobuffalo/pop/v5",
"github.com/markbates/validate": "github.com/gobuffalo/validate/v3",
"github.com/markbates/willie": "github.com/gobuffalo/httptest",
"github.com/satori/go.uuid": "github.com/gofrs/uuid",
"github.com/shurcooL/github_flavored_markdown": "github.com/gobuffalo/github_flavored_markdown",
"github.com/gofrs/uuid": "github.com/gofrs/uuid/v3",
"github.com/gobuffalo/validate": "github.com/gobuffalo/validate/v3",
"github.com/gobuffalo/validate/validators": "github.com/gobuffalo/validate/v3/validators",
"github.com/gobuffalo/suite": "github.com/gobuffalo/suite/v3",
"github.com/gobuffalo/buffalo-pop/": "github.com/gobuffalo/buffalo-pop/v2",
"github.com/gobuffalo/buffalo-pop/pop/popmw": "github.com/gobuffalo/buffalo-pop/v2/pop/popmw",
}

var ic = ImportConverter{
Expand Down
8 changes: 5 additions & 3 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/xml"
"fmt"
"net/http"
"runtime/debug"
"sort"
"strings"

Expand Down Expand Up @@ -81,11 +82,12 @@ func (a *App) PanicHandler(next Handler) Handler {
default:
err = fmt.Errorf(fmt.Sprint(t))
}
err = err
events.EmitError(events.ErrPanic, err,
map[string]interface{}{
"context": c,
"app": a,
"context": c,
"app": a,
"stacktrace": string(debug.Stack()),
"error": err,
},
)
eh := a.ErrorHandlers.Get(http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/gobuffalo/packd v1.0.0
github.com/gobuffalo/packr/v2 v2.8.0
github.com/gobuffalo/plush/v4 v4.0.0
github.com/gobuffalo/pop/v5 v5.0.9
github.com/gobuffalo/pop/v5 v5.0.11
github.com/gobuffalo/tags/v3 v3.1.0
github.com/google/go-cmp v0.4.0
github.com/gorilla/mux v1.7.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ github.com/gobuffalo/pop v4.13.1+incompatible h1:AhbqPxNOBN/DBb2DBaiBqzOXIBQXxEY
github.com/gobuffalo/pop v4.13.1+incompatible/go.mod h1:DwBz3SD5SsHpTZiTubcsFWcVDpJWGsxjVjMPnkiThWg=
github.com/gobuffalo/pop/v5 v5.0.9 h1:F6nT4I2S8tkwBGX0JZePvmOIg1A1VX8Exgcsaak7BfM=
github.com/gobuffalo/pop/v5 v5.0.9/go.mod h1:mZJHJbA3cy2V18abXYuVop2ldEJ8UZ2DK6qOekC5u5g=
github.com/gobuffalo/pop/v5 v5.0.11 h1:BzSFbylk6+w2pEj+8yFHPxsShiJvg6ZV8rcAPNVdmtw=
github.com/gobuffalo/pop/v5 v5.0.11/go.mod h1:mZJHJbA3cy2V18abXYuVop2ldEJ8UZ2DK6qOekC5u5g=
github.com/gobuffalo/release v1.0.35/go.mod h1:VtHFAKs61vO3wboCec5xr9JPTjYyWYcvaM3lclkc4x4=
github.com/gobuffalo/release v1.0.38/go.mod h1:VtHFAKs61vO3wboCec5xr9JPTjYyWYcvaM3lclkc4x4=
github.com/gobuffalo/release v1.0.42/go.mod h1:RPs7EtafH4oylgetOJpGP0yCZZUiO4vqHfTHJjSdpug=
Expand Down
321 changes: 169 additions & 152 deletions packrd/packed-packr.go

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions render/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"net/http"
"path"
"path/filepath"
"reflect"
"strings"

Expand Down Expand Up @@ -113,34 +114,38 @@ func (ir htmlAutoRenderer) Render(w io.Writer, data Data) error {
return err
}
if data["method"] == "PUT" {
return ir.HTML(fmt.Sprintf("%s/edit.html", templatePrefix)).Render(w, data)
return ir.osIndependentHTML(fmt.Sprintf("%s/edit.html", templatePrefix)).Render(w, data)
}
return ir.HTML(fmt.Sprintf("%s/new.html", templatePrefix)).Render(w, data)
return ir.osIndependentHTML(fmt.Sprintf("%s/new.html", templatePrefix)).Render(w, data)
}
return nil
}
cp, ok := data["current_path"].(string)

defCase := func() error {
return ir.HTML(fmt.Sprintf("%s/%s.html", templatePrefix, "index")).Render(w, data)
return ir.osIndependentHTML(fmt.Sprintf("%s/%s.html", templatePrefix, "index")).Render(w, data)
daHaimi marked this conversation as resolved.
Show resolved Hide resolved
}
if !ok {
return defCase()
}

if strings.HasSuffix(cp, "/edit/") {
return ir.HTML(fmt.Sprintf("%s/edit.html", templatePrefix)).Render(w, data)
return ir.osIndependentHTML(fmt.Sprintf("%s/edit.html", templatePrefix)).Render(w, data)
}
if strings.HasSuffix(cp, "/new/") {
return ir.HTML(fmt.Sprintf("%s/new.html", templatePrefix)).Render(w, data)
return ir.osIndependentHTML(fmt.Sprintf("%s/new.html", templatePrefix)).Render(w, data)
}

if !isPlural {
return ir.HTML(fmt.Sprintf("%s/show.html", templatePrefix)).Render(w, data)
return ir.osIndependentHTML(fmt.Sprintf("%s/show.html", templatePrefix)).Render(w, data)
}
return defCase()
}

func (ir htmlAutoRenderer) osIndependentHTML(path string) Renderer {
daHaimi marked this conversation as resolved.
Show resolved Hide resolved
return ir.HTML(filepath.FromSlash(path))
}

func (ir htmlAutoRenderer) redirect(name name.Ident, w io.Writer, data Data) error {
rv := reflect.Indirect(reflect.ValueOf(ir.model))
f := rv.FieldByName("ID")
Expand Down