Skip to content

Commit 5ed669e

Browse files
authored
Merge pull request #88 from authorizerdev/fix/app-code-spliting
Fix/app code spliting
2 parents b4b8593 + 43dce69 commit 5ed669e

File tree

16 files changed

+91
-267
lines changed

16 files changed

+91
-267
lines changed

.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ README.md
66
ROADMAP.md
77
build
88
.env
9-
data.db
9+
data.db
10+
app/node_modules
11+
app/build

.github/workflows/release.yaml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,22 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v2
11+
- uses: actions/setup-node@v2
12+
with:
13+
node-version: '16'
14+
- uses: actions/setup-go@v2
15+
with:
16+
go-version: '^1.17.3'
1117
- name: Install dependencies
1218
run: |
1319
sudo apt-get install build-essential wget zip gcc-mingw-w64 && \
14-
sudo apt-get remove --auto-remove golang-go && \
15-
sudo rm -rf /usr/bin/go &&\
16-
wget --progress=dot:mega https://golang.org/dl/go1.17.1.linux-amd64.tar.gz -O go-linux.tar.gz && \
17-
sudo tar -zxf go-linux.tar.gz && \
18-
sudo mv go /usr/bin/ && \
19-
sudo mkdir -p /go/bin /go/src /go/pkg && \
20-
export GO_HOME=/usr/bin/go && \
21-
export GOPATH=/go && \
22-
export PATH=${GOPATH}/bin:${GO_HOME}/bin/:$PATH && \
23-
echo "/usr/bin/go/bin" >> $GITHUB_PATH
24-
echo "/usr/bin/x86_64-w64-mingw32-gcc" >> GITHUB_PATH
25-
go version && \
20+
echo "/usr/bin/x86_64-w64-mingw32-gcc" >> GITHUB_PATH && \
2621
wget --no-check-certificate --progress=dot:mega https://github.com/wangyoucao577/assets-uploader/releases/download/v0.3.0/github-assets-uploader-v0.3.0-linux-amd64.tar.gz -O github-assets-uploader.tar.gz && \
2722
tar -zxf github-assets-uploader.tar.gz && \
2823
sudo mv github-assets-uploader /usr/sbin/ && \
2924
sudo rm -f github-assets-uploader.tar.gz && \
30-
github-assets-uploader -version
25+
github-assets-uploader -version && \
26+
make build-app
3127
- name: Print Go paths
3228
run: whereis go
3329
- name: Print Go Version

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ server/server
22
server/.env
33
data
44
app/node_modules
5+
app/build
56
build
67
.env
78
data.db

Dockerfile

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
FROM golang:1.17-alpine as builder
2-
WORKDIR /app
1+
FROM golang:1.17-alpine as go-builder
2+
WORKDIR /authorizer
33
COPY server server
44
COPY Makefile .
55

66
ARG VERSION="latest"
77
ENV VERSION="$VERSION"
88

99
RUN echo "$VERSION"
10-
RUN apk add build-base nodejs &&\
10+
RUN apk add build-base &&\
1111
make clean && make && \
1212
chmod 777 build/server
1313

14+
FROM node:17-alpine3.12 as node-builder
15+
WORKDIR /authorizer
16+
COPY app app
17+
COPY Makefile .
18+
RUN apk add build-base &&\
19+
make build-app
20+
1421
FROM alpine:latest
15-
RUN apk --no-cache add ca-certificates
1622
WORKDIR /root/
17-
COPY app app
23+
RUN mkdir app
24+
COPY --from=node-builder /authorizer/app/build app/build
25+
COPY --from=go-builder /authorizer/build build
1826
COPY templates templates
19-
COPY --from=builder /app/build build
2027
EXPOSE 8080
2128
CMD [ "./build/server" ]

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ VERSION := $(or $(VERSION),$(DEFAULT_VERSION))
33

44
cmd:
55
cd server && go build -ldflags "-w -X main.VERSION=$(VERSION)" -o '../build/server'
6+
build-app:
7+
cd app && npm i && npm run build
68
clean:
79
rm -rf build
810
test:

app/build/bundle.css

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/build/bundle.js

Lines changed: 0 additions & 195 deletions
This file was deleted.

app/build/bundle.js.map

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/esbuild.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const __is_prod__ = process.env.NODE_ENV === 'production';
2+
require('esbuild').build({
3+
entryPoints: ['src/index.tsx'],
4+
chunkNames: '[name]-[hash]',
5+
bundle: true,
6+
minify: __is_prod__,
7+
outdir: 'build',
8+
splitting: true,
9+
format: 'esm',
10+
watch: !__is_prod__,
11+
});

app/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"build": "esbuild src/index.tsx --bundle --minify --sourcemap --outfile=build/bundle.js"
7+
"build": "rm -rf build && NODE_ENV=production node ./esbuild.config.js",
8+
"start": "NODE_ENV=development node ./esbuild.config.js"
89
},
910
"keywords": [],
1011
"author": "Lakhan Samani",
1112
"license": "ISC",
1213
"dependencies": {
13-
"@authorizerdev/authorizer-react": "^0.3.0",
14+
"@authorizerdev/authorizer-react": "latest",
1415
"@types/react": "^17.0.15",
1516
"@types/react-dom": "^17.0.9",
1617
"esbuild": "^0.12.17",

0 commit comments

Comments
 (0)