Skip to content

Commit

Permalink
Revert "Organize codebase files into folders and install MySql in dev…
Browse files Browse the repository at this point in the history
…container automatically (#207)"

This reverts commit 9ff2461.
  • Loading branch information
jakehobbs committed Apr 6, 2024
1 parent 9ff2461 commit 5d6f3c7
Show file tree
Hide file tree
Showing 100 changed files with 74 additions and 322 deletions.
7 changes: 0 additions & 7 deletions .devcontainer/Dockerfile

This file was deleted.

10 changes: 4 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/debian
{
"name": "DxE ADB",
"build": {
"dockerfile": "Dockerfile"
},
"name": "Debian",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:bullseye",

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
Expand All @@ -29,8 +28,7 @@
"extensions": [
"ms-vscode.makefile-tools",
"golang.go",
"Vue.volar",
"GitHub.vscode-github-actions"
"Vue.volar"
]
}
},
Expand Down
31 changes: 0 additions & 31 deletions .devcontainer/install-mysql.sh

This file was deleted.

3 changes: 0 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ jobs:
go version
- name: Install deps
run: |
cd ./frontend
npm ci --legacy-peer-deps
cd ../server/src
go mod download
- name: Start database
run: |
Expand All @@ -39,7 +37,6 @@ jobs:
- name: Run tests
run: |
./hooks/pre-commit
cd ./server/src
go test github.com/dxe/adb/...
- name: Deploy image to ECR
if: ${{ github.event_name == 'push' }} # don't deploy branches
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
adb
adb-config
adb.db
frontend/dist
frontend/node_modules
dist
docker-compose.yml
node_modules
npm-debug.log
File renamed without changes.
27 changes: 21 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,44 @@

FROM golang:latest AS build-api
WORKDIR /src
COPY server/src ./
COPY go.mod go.sum ./
RUN GOFLAGS=-mod=readonly GOPROXY=https://proxy.golang.org go mod download
COPY main.go ./
COPY config config/
COPY google_groups_sync google_groups_sync/
COPY survey_mailer survey_mailer/
COPY international_mailer international_mailer/
COPY mailer mailer/
COPY event_sync event_sync/
COPY form_processor form_processor/
COPY members members/
COPY model model/
COPY discord discord/
COPY mailing_list_signup mailing_list_signup/
RUN CGO_ENABLED=0 go build -o adb


## Build web UI frontend.

FROM node:16 AS build-ui

WORKDIR /src
COPY frontend ./
COPY package.json package-lock.json ./
RUN npm ci --legacy-peer-deps
COPY tsconfig.json webpack.config.js ./
COPY frontend frontend/
RUN npm run build


## Assemble composite server container.

FROM alpine:latest
RUN apk add --no-cache ca-certificates tzdata
RUN addgroup -S adb && adduser -S adb -G adb

WORKDIR /app
COPY server/run.sh ./
COPY server/templates templates/
COPY frontend/static static/
COPY run.sh ./
COPY static static/
COPY templates templates/
COPY --from=build-api /src/adb ./
COPY --from=build-ui /src/dist dist/

Expand Down
45 changes: 15 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,56 @@

# Runs the application.
run_all:
cd frontend && npm run dev-build
npm run dev-build
$(MAKE) run

# Just start the go program without recompiling the JS.
run:
cd server/src && go install # Install first so that we keep cached build objects around.

cd server/src; \
export TEMPLATES_DIRECTORY=../templates; \
export STATIC_DIRECTORY=../../frontend/static; \
export DIST_DIRECTORY=../../frontend/dist; \
go install # Install first so that we keep cached build objects around.
go run main.go

# Builds the frontend JS.
js:
cd frontend && npm run dev-build
npm run dev-build

# Automatically rebuild the JS when you edit a JS file. This is more
# convenient then manually running `make run_all` every time you
# update the JS. You'll need to do this in a separate terminal.
watch:
cd frontend && npm run watch
npm run watch

# Wipe and re-create the dev databases. See the readme for more
# details.
dev_db:
cd server/scripts/create_db_wrapper && ./create_db_wrapper.sh
./scripts/create_db_wrapper.sh

# Install all deps for this project.
deps:
cd frontend && npm install --legacy-peer-deps
cd server/src && go get -t github.com/dxe/adb/...
npm install --legacy-peer-deps
go get -t github.com/dxe/adb/...

# Run all tests
test:
cd server/src && go test ./...
go test ./...

# Clean all built outputs
clean:
rm -f server/adb
rm -rf frontend/dist
rm -f adb
rm -rf dist

# Set git hooks
set_git_hooks:
if [ ! -h .git/hooks/pre-commit ] ; then ln -s ../../hooks/pre-commit .git/hooks/pre-commit ; fi
if [ ! -h .git/hooks/pre-push ] ; then ln -s ../../hooks/pre-push .git/hooks/pre-push ; fi


# Test docker image
docker_run:
docker build . -t dxe/adb
docker container run --rm -p 8080:8080 -it --name adbtest dxe/adb

# Open shell inside docker container while it's running
docker_shell:
docker exec -it adbtest /bin/ash

# Build the project for production.
prod_build: clean set_git_hooks
cd server && ./scripts/pull_adb_config.sh
cd frontend && npm run build
cd server/src && env GOOS=linux GOARCH=amd64 go build
./scripts/pull_adb_config.sh
npm run build
env GOOS=linux GOARCH=amd64 go build

# Reformat source files.
# Keep in sync with hooks/pre-commit.
fmt:
cd server && gofmt -w `find . -name '*.go'`
cd frontend && npx prettier --write *.{ts,vue,js}
gofmt -w `find . -name '*.go'`
npx prettier --write frontend/*.{ts,vue}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ make deps
There is now a Docker container to run MySQL locally, so just run the following:

```bash
( cd server/ && docker compose up -d )
docker compose up -d
make dev_db
```

Expand All @@ -47,7 +47,7 @@ Please run `make fmt` and `make test` before sending a pull request.

This project uses webpack to compile our frontend files. Frontend
files that need to be compiled are in `frontend/`, and the compiled
outputs are in `frontend/dist/`.
outputs are in `dist/`.

* package.json: file with all frontend dependencies

Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions server/src/config/config.go → config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ var (
CookieSecret = mustGetenv("COOKIE_SECRET", "some-fake-secret", true)
CsrfAuthKey = mustGetenv("CSRF_AUTH_KEY", "", true)

TemplatesDirectory = mustGetenv("TEMPLATES_DIRECTORY", "./templates", true)
StaticDirectory = mustGetenv("STATIC_DIRECTORY", "./static", true)
DistDirectory = mustGetenv("DIST_DIRECTORY", "./dist", true)

// Path to Google API oauth client_secrets.json file, with
// access to the following scope:
// https://www.googleapis.com/auth/admin.directory.group
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 7 additions & 9 deletions server/src/main.go → main.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,13 @@ func router() (*mux.Router, *sqlx.DB) {
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
router.HandleFunc("/debug/pprof/trace", pprof.Trace)

var staticHandler = http.StripPrefix("/static/", http.FileServer(http.Dir(config.StaticDirectory)))
var distHandler = http.StripPrefix("/dist/", http.FileServer(http.Dir(config.DistDirectory)))
if !config.IsProd {
staticHandler = noCacheHandler(staticHandler)
distHandler = noCacheHandler(distHandler)
if config.IsProd {
router.PathPrefix("/static").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
router.PathPrefix("/dist").Handler(http.StripPrefix("/dist/", http.FileServer(http.Dir("dist"))))
} else {
router.PathPrefix("/static").Handler(noCacheHandler(http.StripPrefix("/static/", http.FileServer(http.Dir("static")))))
router.PathPrefix("/dist").Handler(noCacheHandler(http.StripPrefix("/dist/", http.FileServer(http.Dir("dist")))))
}
router.PathPrefix("/static").Handler(staticHandler)
router.PathPrefix("/dist").Handler(distHandler)

return router, db
}

Expand Down Expand Up @@ -747,7 +745,7 @@ var templates = template.Must(template.New("").Funcs(
}
return input
},
}).ParseGlob(config.TemplatesDirectory + "/*.html"))
}).ParseGlob("templates/*.html"))

type UserChapter struct {
ID int
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ if [ -z ${DXE_DEV_EMAIL+x} ]; then
echo "Please enter your development email or set DXE_DEV_EMAIL to never see this message again: "
read DXE_DEV_EMAIL
fi
go run ./create_db.go --dev-email="${DXE_DEV_EMAIL}"
go run ./scripts/create_db.go --dev-email="${DXE_DEV_EMAIL}"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 0 additions & 7 deletions server/scripts/create_db_wrapper/go.mod

This file was deleted.

Loading

0 comments on commit 5d6f3c7

Please sign in to comment.