Skip to content

Commit f720ff5

Browse files
authored
[misc: Reduce build complexity (#17)
* reduce build complexity * use vite * pagination (work in progress) * refetch on party event * prepare release
1 parent e86221d commit f720ff5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3159
-29169
lines changed

Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Go
22
FROM golang:1.19-alpine AS go-builder
3-
RUN apk add --no-cache make upx
3+
RUN apk add --no-cache upx
44

5-
WORKDIR /app
5+
WORKDIR /app
66
COPY api .
7-
RUN make go-build-for-docker
7+
RUN go mod download
8+
RUN go build -o bin/group-challenge --tags release -ldflags "-s -w"
9+
RUN upx bin/group-challenge
810

911
#########
1012

@@ -22,12 +24,12 @@ RUN npm run build
2224
#########
2325

2426
# Executable
25-
FROM alpine
27+
FROM alpine:3.16
2628
RUN apk --no-cache add ca-certificates
2729

2830
WORKDIR /app
29-
COPY --from=go-builder /app/group-challenge .
30-
COPY --from=react-builder /app/build/ ./static
31+
COPY --from=go-builder /app/bin/group-challenge .
32+
COPY --from=react-builder /app/dist/ ./static
3133

3234
ENV GIN_MODE=release
3335
CMD [ "./group-challenge" ]

README.md

Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,23 @@
33
[![Docker](https://github.com/subshell/group-challenge/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/subshell/group-challenge/actions/workflows/docker-publish.yml)
44

55
An easy-to-use website to create submission-based challenges that will be evaluated together in real-time.
6-
Any user is allowed to create challenges with a fixed start and end date while others join and
7-
contribute. Currently supported challenges are:
6+
Any user is allowed to create challenges with a fixed start and end date while others join and contribute.
7+
Currently supported challenges are:
88

99
- 📸 **Photo Challenge**
1010

1111
![Start Screen](.github/start_screen.png)
1212

13-
## Local development
14-
15-
This project includes pre-configured configuration files to launch the api, frontend, and postgres in VS Code. Alternatively you can start all services with the following commands:
16-
17-
1. **Postgres:** start a postgres db at port `5432`.
18-
19-
```sh
20-
mkdir /tmp/group-challenge-cache
21-
docker-compose up
22-
```
23-
24-
2. **API:** start the go api server at port `8080`.
25-
26-
```sh
27-
cd api && go run ./cmd/group-challenge/root.go
28-
```
13+
## Configuration
2914

30-
3. **Frontend:** start the frontend at port `3000`.
31-
32-
```sh
33-
cd frontend && npm start
34-
```
15+
The configuration is usally located under `/app/config.yaml`.
16+
We also support configuration via environment variabels with a `GC_` prefix:
3517

36-
## Run in Docker
18+
- `GC_SERVER_PORT`
19+
- `GC_DB_USER`
20+
- `GC_DB_PASSWORD`
3721

38-
The Dockerimage requires a config file `/app/config.yaml`. Env variables are also supported. They have a `GC_` prefix,
39-
for example: `GC_SERVER_PORT`. The postgreSQL database is not part of the Dockerimage and has to be started separately.
22+
**All available configuration options:**
4023

4124
```yaml
4225
server:
@@ -60,7 +43,62 @@ imgProxy:
6043
fullSizeQuality: 75
6144
```
6245
63-
### Kubernetes support
46+
## Local development
47+
48+
This project includes pre-configured configuration files to launch the api, frontend, and postgres in VS Code.
49+
Alternatively you can start all services with the following commands:
50+
51+
1. **Postgres:** start a postgres db at port `5432`.
52+
53+
```sh
54+
mkdir /tmp/group-challenge-cache
55+
docker-compose up
56+
```
57+
58+
2. **API:** start the go api server at port `8080`.
59+
60+
```sh
61+
cd api && go run ./cmd/group-challenge/root.go
62+
```
63+
64+
3. **Frontend:** start the frontend at port `3000`.
65+
66+
```sh
67+
cd frontend && npm run dev
68+
```
69+
70+
## Container
71+
72+
For official container images visit https://github.com/subshell/group-challenge/pkgs/container/group-challenge
73+
74+
### Building the container
75+
76+
The container contains the frontend as well as the backend.
77+
78+
```sh
79+
docker build . --tag group-challenge
80+
```
81+
82+
### Running the container
83+
84+
Before you can run the `group-challenge` container, make sure that postgresql and optionally imgProxy is running.
85+
You can start both applications with `mkdir /tmp/group-challenge-cache && docker-compose up`.
86+
87+
By default you can open your browser at http://localhost:8080/ to see the running group-challenge app.
88+
89+
#### Your localy created container
90+
91+
```sh
92+
docker run --network=host group-challenge
93+
```
94+
95+
#### Official container
96+
97+
```sh
98+
docker run --network=host ghcr.io/subshell/group-challenge:latest
99+
```
100+
101+
## Kubernetes support
64102

65103
The helm chart is available under https://subshell.github.io/helm-charts-lab/
66104

@@ -78,8 +116,6 @@ You definitely want to change the password using `global.postgresql.postgresqlPa
78116

79117
To reduce the size of all uploaded images, we support [imgProxy](https://docs.imgproxy.net). See `imgProxy` for its configuration.
80118

81-
82-
* * *
119+
---
83120

84121
Take a look at this project from the [subshell](https://subshell.com) team. We make [Sophora](https://subshell.com/sophora/): a content management software for content creation, curation, and distribution. [Join our team!](https://subshell.com/jobs/) | [Imprint](https://subshell.com/about/imprint/)
85-

api/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ vendor
2020

2121
__debug_bin
2222
tmp
23-
/group-challenge
23+
bin/group-challenge

api/Makefile

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

api/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
## Run locally
44

5-
make go-run
5+
go run main.go
66

7-
## Build Package
7+
## Build package
88

9-
make go-build
9+
go build -o bin/group-challenge
10+
11+
## Reduce package size
12+
13+
upx bin/group-challenge

api/go.mk

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

api/cmd/group-challenge/root.go renamed to api/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ func init() {
2828
// config defaults
2929
viper.SetDefault("server.port", 8080)
3030
viper.SetDefault("server.staticFilesDir", "./static")
31-
viper.SetDefault("db.User", "")
32-
viper.SetDefault("db.Password", "")
33-
viper.SetDefault("db.Database", "postgres")
34-
viper.SetDefault("db.Host", "localhost:5432")
35-
viper.SetDefault("db.PoolSize", 50)
31+
viper.SetDefault("db.user", "")
32+
viper.SetDefault("db.password", "")
33+
viper.SetDefault("db.database", "postgres")
34+
viper.SetDefault("db.host", "localhost:5432")
35+
viper.SetDefault("db.poolSize", 50)
3636
viper.SetDefault("challenges.party.live.defaultTimePerSubmissionSeconds", 45)
3737
viper.SetDefault("imgProxy.enabled", false)
3838
viper.SetDefault("imgProxy.url", "http://localhost:8081")
39-
viper.SetDefault("imgProxy.SharedLocalCacheDir", "/tmp/group-challenge-cache")
39+
viper.SetDefault("imgProxy.sharedLocalCacheDir", "/tmp/group-challenge-cache")
4040
viper.SetDefault("imgProxy.thumbnailQuality", 75)
4141
viper.SetDefault("imgProxy.fullSizeQuality", 75)
4242
viper.SetDefault("imgProxy.maxFullWidth", 1280)

api/pkg/group-challenge/api/party-api.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"mime/multipart"
1212
"net/http"
1313
"path/filepath"
14+
"strconv"
1415
"time"
1516

1617
"github.com/gin-gonic/gin"
@@ -30,6 +31,12 @@ type partyRequestBody struct {
3031
EndDate time.Time `json:"endDate"`
3132
}
3233

34+
type paginationResponseBody struct {
35+
PageSize int `json:"pageSize"`
36+
Page int `json:"page"`
37+
Data []*models.Party `json:"data"`
38+
}
39+
3340
type partySubmissionMetaBody struct {
3441
Name string `json:"name"`
3542
Description string `json:"description"`
@@ -52,16 +59,34 @@ func broadcastParty(operation string, party *models.Party) {
5259
}
5360

5461
func partiesHandler(c *gin.Context) {
62+
pageSize := 5
63+
64+
pageString := c.Request.URL.Query().Get("page")
65+
if pageString == "" {
66+
pageString = "0"
67+
}
68+
page, err := strconv.Atoi(pageString)
69+
if err != nil {
70+
log.Println("[ERROR]", "page param is not an integer", pageString)
71+
c.Status(http.StatusBadRequest)
72+
return
73+
}
74+
5575
parties := []*models.Party{}
56-
err := models.GetAllParties(&parties, con)
76+
err = models.GetAllParties(&parties, page, pageSize, con)
5777

5878
if err != nil {
5979
log.Println("[ERROR]", err)
6080
c.Status(500)
6181
return
6282
}
6383

64-
c.JSON(200, parties)
84+
response := paginationResponseBody{}
85+
response.Data = parties
86+
response.Page = page
87+
response.PageSize = pageSize
88+
89+
c.JSON(200, response)
6590
}
6691

6792
func addPartyHandler(c *gin.Context) {

api/pkg/group-challenge/models/party-model.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ func (submission *PartySubmission) Update(con *pg.DB) error {
132132
}
133133

134134
// GetAllParties returns all parties
135-
func GetAllParties(parties *[]*Party, con *pg.DB) error {
136-
err := con.Model(parties).Limit(200).Select()
135+
func GetAllParties(parties *[]*Party, page int, limit int, con *pg.DB) error {
136+
err := con.Model(parties).Offset(page * limit).Limit(limit).Order("end_date desc").Select()
137137

138138
if err != nil {
139139
return err

frontend/.gitignore

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
29

3-
# dependencies
410
node_modules
5-
/.pnp
6-
.pnp.js
7-
8-
# testing
9-
coverage
10-
11-
# production
12-
build
11+
dist
12+
dist-ssr
13+
*.local
1314

14-
# misc
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
1519
.DS_Store
16-
.env.local
17-
.env.development.local
18-
.env.test.local
19-
.env.production.local
20-
21-
npm-debug.log*
22-
yarn-debug.log*
23-
yarn-error.log*
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

0 commit comments

Comments
 (0)