Skip to content

Commit

Permalink
Merge branch 'Granola-Team:main' into mf-main
Browse files Browse the repository at this point in the history
  • Loading branch information
kaozenn authored Nov 28, 2023
2 parents ff43708 + 4a4fa78 commit 27b8cac
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 426 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DB_NAME=db
DATABASE_URL=postgresql://granola:[email protected]:5432/db

# [REQUIRED] - the connection URL for the archive database.
# ARCHIVE_DATABASE_URL=postgresql://granola:[email protected]:5432/db
ARCHIVE_DATABASE_URL=postgresql://granola:[email protected]:5432/db

# [REQUIRED] - origins allowed to make cross-site requests.
# Use "*" to allow from anywhere.
Expand Down
55 changes: 0 additions & 55 deletions .github/workflows/server.yml

This file was deleted.

71 changes: 0 additions & 71 deletions .github/workflows/web.yml

This file was deleted.

157 changes: 43 additions & 114 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@
# The command 'just' will give usage information.
# See https://github.com/casey/just for more.

# Default build target. Shows menu of targets which user runs 'just'.
#
default:
@just --list --justfile {{justfile()}}

# Variables
#
DB_HOST := env_var_or_default('DB_HOST', "127.0.0.1")
DB_PORT := env_var_or_default('DB_PORT', "5432")
DB_NAME := env_var_or_default('DB_NAME', "db")
DB_USER := env_var_or_default('DB_USER', "granola")
DB_PASS := env_var_or_default('DB_PASS', "systems")
DATABASE_URL := env_var_or_default(
'DATABASE_URL',
"postgresql://" + DB_USER + ":" + DB_PASS + "@" + DB_HOST + ":" + DB_PORT + "/" + DB_NAME)
container_log_dir := `mktemp -d "${TMPDIR:-/tmp}"/container-logs-XXX`
set dotenv-load

#
# Targets
Expand Down Expand Up @@ -67,17 +55,7 @@ build-server: lint-server

test: test-web

test-web: test-server launch-web

test-server: launch-server
sleep 10 # Wait for server to launch.
curl http://127.0.0.1:8080/api/info | grep 'chain_tip'
grep DEBUG {{ container_log_dir }}/server.err # Ensure DEBUG info being logged.
curl http://127.0.0.1:8080/api/proposals \
| grep 'jw8dXuUqXVgd6NvmpryGmFLnRv1176oozHAro8gMFwj8yuvhBeS'
grep "status.*200.*/api/proposals" {{ container_log_dir }}/server.err
curl http://127.0.0.1:8080/api/proposal/4/results | grep 'MIP4'
grep "status.*200.*/api/proposal/4/result" {{ container_log_dir }}/server.err
test-web: destroy-all launch-web && destroy-all

lint: lint-web lint-server

Expand All @@ -97,107 +75,58 @@ lint-server: install-server
image-build: image-build-web image-build-server

# Build the container image for 'web'
[macos]
image-build-web: clean-web
docker build -t mina-ocv-web ./web

# Build the container image for 'web'
[linux]
image-build-web: clean-web
podman build -t mina-ocv-web ./web

# Build the container image for 'server'
[macos]
image-build-server: clean-server
docker build -t mina-ocv-server ./server

# Build the container image for 'server'
[linux]
image-build-server: clean-server
podman build -t mina-ocv-server ./server

[macos]
destroy-db:
docker-compose --profile=db down

[linux]
destroy-db:
-podman stop db
-podman container rm db
docker-compose down db

[macos]
destroy-server:
docker-compose --profile=server-db down

[linux]
destroy-server:
-podman stop server
-podman container rm server

[macos]
destroy-web:
docker-compose --profile=all down
docker-compose down server

[linux]
destroy-web:
-podman stop web
-podman container rm web
docker-compose down web

# Stop and destroy all known containers.
destroy-all: destroy-db destroy-server destroy-web

# Run the database container with migrations applied.
[linux]
launch-db: destroy-db
podman run \
--name db \
-e POSTGRES_DB={{ DB_NAME }} \
-e POSTGRES_USER={{ DB_USER }} \
-e POSTGRES_PASSWORD={{ DB_PASS }} \
-e DATABASE_URL={{ DATABASE_URL }} \
--expose {{ DB_PORT }} \
--network host \
postgres:15.2 \
> {{ container_log_dir }}/db.out \
2> {{ container_log_dir }}/db.err &
sleep 2
cd server && \
DATABASE_URL={{ DATABASE_URL }} diesel migration run

# Running 'diesel migration run' actually makes changes to the source files!
# WTF! This undoes that change.
git restore -- server/src/schema.rs

[macos]
launch-server: destroy-server image-build-server
docker-compose --profile=server-db up \
> {{ container_log_dir }}/server.out \
2> {{ container_log_dir }}/server.err &

[linux]
launch-server: destroy-server image-build-server launch-db
podman run \
--name server \
--env-file .env \
--expose 8080 \
--network host \
localhost/mina-ocv-server:latest \
> {{ container_log_dir }}/server.out \
2> {{ container_log_dir }}/server.err &

[macos]
launch-web: destroy-all image-build-server image-build-web
docker-compose --profile=all up \
> {{ container_log_dir }}/web.out \
2> {{ container_log_dir }}/web.err &

[linux]
launch-web: destroy-all image-build-web launch-server
podman run \
--name web \
--env-file .env \
--expose 3000 \
--network host \
localhost/mina-ocv-web:latest \
> {{ container_log_dir }}/web.out \
2> {{ container_log_dir }}/web.err &
destroy-all:
docker-compose down
docker network prune -f

launch-db:
docker-compose up -d db

test-db: destroy-all launch-db && destroy-all
# Wait for the container to attach to the port.
sleep 5
# Wait for up to 1 minute for the database instance to be ready.
pg_isready \
-h "$DB_HOST" \
-p "$DB_PORT" \
-d "$DB_NAME" \
-U "$DB_USER" \
-t 60
docker-compose logs db \
| grep "database system is ready to accept connections"

launch-server:
docker-compose up -d server

test-server: destroy-all launch-server && destroy-all
sleep 20 # Wait for server to launch.
curl http://127.0.0.1:8080/api/info | grep 'chain_tip'
docker-compose logs server 2>&1 \
| grep DEBUG # Ensure DEBUG info being logged.
curl http://127.0.0.1:8080/api/proposals \
| grep 'jw8dXuUqXVgd6NvmpryGmFLnRv1176oozHAro8gMFwj8yuvhBeS'
docker-compose logs server 2>&1 \
| grep "status.*200.*/api/proposals"
curl http://127.0.0.1:8080/api/proposal/4/results | grep 'MIP4'
docker-compose logs server 2>&1 \
| grep "status.*200.*/api/proposal/4/result"

launch-web:
docker-compose up -d web
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build status](https://badge.buildkite.com/521caf4796d8f12a30ce6ca712f917715db81be9bbc265b6df.svg)](https://buildkite.com/granola/mina-on-chain-voting)

# Mina On-Chain Voting

On-Chain Voting is a protocol developed to help with governing the Mina L1
Expand Down
24 changes: 15 additions & 9 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
version: '3.8'
networks:
mina-ocv:
name: "mina-ocv${BUILDKITE_BUILD_NUMBER-}"
services:
web:
container_name: web
profiles: ['all', 'web']
build:
context: ./web
dockerfile: Dockerfile
image: mina-ocv-web:latest
env_file: .env
environment:
- API_BASE_URL=http://server:8080
- NEXT_PUBLIC_API_BASE_URL=http://server:8080
- RELEASE_STAGE=production
ports:
- 3000:3000
networks:
- mina-ocv
depends_on:
- db
- server
server:
container_name: server
profiles: ['all', 'server-db', 'server']
build:
context: ./server
dockerfile: Dockerfile
image: mina-ocv-server:latest
env_file: .env
environment:
- DB_HOST=db
- DATABASE_URL=postgresql://granola:systems@db:5432/db
ports:
- 8080:8080
networks:
- mina-ocv
depends_on:
- db
db:
container_name: postgres
profiles: ['all', 'server-db', 'db']
image: postgres:15.2
env_file: .env
ports:
- 5432:5432
networks:
- mina-ocv
environment:
POSTGRES_USER: granola
POSTGRES_PASSWORD: systems
Expand Down
Loading

0 comments on commit 27b8cac

Please sign in to comment.