Skip to content

Commit

Permalink
feat: restart project
Browse files Browse the repository at this point in the history
  • Loading branch information
XGHeaven committed Oct 19, 2023
1 parent e835fd1 commit affe300
Show file tree
Hide file tree
Showing 23 changed files with 5,278 additions and 10,010 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/build-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@ jobs:
- uses: actions/checkout@v2

- name: Bootstrap
run: |
cd server
go mod download
cd ../web
rm -f package-lock.json
npm i --registry=https://registry.npmjs.org/
- name: Install go-bindata
run: |
export PATH=$PATH:$(go env GOPATH)/bin
go get -u github.com/go-bindata/go-bindata/...
make bootstrap
echo "go-bindata version:" $(go-bindata -version)
- name: Build frontend assets
run: |
Expand Down
41 changes: 8 additions & 33 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,21 @@
## server
FROM golang:1.14 AS server-build-env

WORKDIR /app

COPY server/go.* ./server/

RUN go get -u github.com/go-bindata/go-bindata/...

RUN cd server && go mod download

## web
FROM node:lts as web-build-env

FROM node:lts as web-build
WORKDIR /app

COPY web/package.json ./web/

RUN cd web && npm i

FROM web-build-env AS web-build

COPY Makefile ./

COPY web/ ./web/
RUN corepack enable && make bootstrap-web && make build-web

RUN make build-web

FROM server-build-env AS server-build

## server
FROM golang:1.21 AS server-build
WORKDIR /app
COPY Makefile ./

COPY server/*.go ./server/
COPY server/ ./server/
COPY --from=web-build /app/build/static/ /app/build/static

RUN make build-server
RUN go install github.com/go-bindata/go-bindata/...@v3
RUN make bootstrap-server && make build-server

FROM alpine

WORKDIR /app

EXPOSE 3300

COPY --from=server-build /app/build/server /app/server

CMD [ "./server" ]
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
bootstrap:
cd server && go mod download
cd web && npm i
mkdir -p build/static
make build-dev-assets
bootstrap: bootstrap-web bootstrap-server

bootstrap-web:
cd web && pnpm install

bootstrap-build:
bootstrap-server:
go install github.com/go-bindata/go-bindata/...@v3
cd server && go mod download
cd web && npm i

run-server:
cd server && go run .
Expand All @@ -18,13 +17,14 @@ build-server: build-assets
cd server && CGO_ENABLED=0 go build -ldflags "-X main.ENV=production" -o ../build/server ./

build-web:
cd web && npm run build
cd web && pnpm run build

build-assets:
go-bindata -fs -o server/assets.go -prefix build/static build/static

build-dev-assets:
go-bindata -fs -debug -o server/assets.go -prefix build/static build/static
# go-bindata -fs -debug -o server/assets.go -prefix build/static build/static
go-bindata -fs -o server/assets.go -prefix build/static build/static

build: build-web build-server

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

- 在 2017 款 13 寸 Macbook 上,低速配置下能够实现 4G 下载速度以及 3G 上传速度
- 在 2019 款 16 寸 Macbook 上,在开启高速模式下,最高可以达到 12G 的下载速度以及 10G 的上传速度
- 在 AMD 3600 的设备上,高速模式下可以达到 15G 的下载速度以及 12G 的上传速度

## Powered by

Expand Down
6 changes: 6 additions & 0 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"
"strconv"
"time"
"fmt"

"github.com/gin-gonic/gin"
)
Expand All @@ -19,6 +20,9 @@ const (

func main() {
isProd := ENV == "production"
if isProd {
gin.SetMode(gin.ReleaseMode)
}
r := gin.Default()

if isProd {
Expand Down Expand Up @@ -107,5 +111,7 @@ func main() {
})
})

fmt.Println("Listened on :3300")

r.Run(":3300")
}
Loading

0 comments on commit affe300

Please sign in to comment.