Skip to content

Commit

Permalink
Merge branch 'fix/setup-dev-env' into 'beta'
Browse files Browse the repository at this point in the history
Fix/setup dev env

See merge request voltaire/govtool-outcomes-pillar!5
  • Loading branch information
Darlington Wleh committed Jan 20, 2025
2 parents bd5f981 + a3ac647 commit 3d4db54
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 59 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/govtool/
.idea
/node_modules/
/node_modules/
*.cjs
17 changes: 0 additions & 17 deletions Dockerfile.govtool

This file was deleted.

27 changes: 17 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
init:
make ui-install
make backend-install
docker compose up -d
make govtool-install
chmod -R 777 ./start-govtool.sh
./start-govtool.sh
docker compose up

.PHONY: up
up:
docker compose up -d

# run this independently incase govtool has new libraries from the git pull
# make govtool-install
docker compose up

.PHONY: down
down:
docker compose down

.PHONY: update-govtool
update-govtool:
./start-govtool.sh true

.PHONY: ui-install
ui-install:
make ui-clean
Expand All @@ -36,6 +38,7 @@ backend-install:

.PHONY: govtool-install
govtool-install:
rm -rf govtool/frontend/node_modules 2>/dev/null || true
docker run --rm --interactive --tty \
--volume ${PWD}/govtool/frontend/:/app \
--workdir /app \
Expand All @@ -46,23 +49,27 @@ govtool-install:
backend-clean:
rm -rf backend/node_modules 2>/dev/null || true


.PHONY: ui-clean
ui-clean:
rm -rf ui/node_modules 2>/dev/null || true


.PHONY: image-build-ui
image-build-ui:
docker build \
-f ui/Dockerfile.dev \
-t outcomes-pillar-ui \
ui/.


.PHONY: image-build-backend
image-build-backend:
docker build \
-f backend/Dockerfile.dev \
-t outcomes-pillar-backend \
backend/.
backend/.

.PHONY: image-build-govtool
image-build-govtool:
docker build \
-f ./Dockerfile.govtool \
-t govtool_frontend \
.
29 changes: 19 additions & 10 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
services:

outcomespillar.backend:
image: outcomes-pillar-backend:latest
build:
Expand All @@ -23,34 +22,44 @@ services:
context: ./ui/
dockerfile: Dockerfile.dev
container_name: outcomespillar-ui
entrypoint: ["sh", "-c", "npm run watch"]
entrypoint: ["sh", "-c", " npm run watch"]
environment:
- NODE_ENV=development
- ROLLUP_WATCH=true
extra_hosts:
- 'host.docker.internal:host-gateway'
volumes:
- './ui:/usr/src/app:cached'
- './ui:/app/govtool/frontend/node_modules/@lidonation/govtool-outcomes-pillar-ui'
networks:
- govtool

govtool.frontend:
image: govtool_frontend
build:
context: ./
dockerfile: Dockerfile.govtool
tty: true
image: node:20-alpine
container_name: govtool-frontend
command: npx vite --host --port 5173
working_dir: /app/govtool/frontend
entrypoint: ["sh", "-c", "cd /app/ui && npm link && \
cd /app/govtool/frontend && npm link @intersect.mbo/govtool-outcomes-pillar-ui && \
npx vite --host --port 5173"]
ports:
- "5173:5173"
environment:
- VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED=true
- VITE_IS_GOVERNANCE_OUTCOMES_PILLAR_ENABLED=true
- VITE_APP_ENV=development
extra_hosts:
- 'host.docker.internal:host-gateway'
volumes:
- './govtool/frontend:/app/govtool/frontend:cached'
- './govtool/frontend:/app/govtool/frontend'
- './ui/:/app/ui'
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5173"]
interval: 30s
timeout: 10s
retries: 3
networks:
- govtool

networks:
govtool:
driver: bridge
77 changes: 56 additions & 21 deletions start-govtool.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,68 @@
#!/bin/bash

set -e # Exit immediately if a command exits with a non-zero status
set -e

echo "Starting repository update process..."
echo "Starting govtool setup..."

# Ensure the repository is up-to-date
cd /app
REPO_URL="https://github.com/IntersectMBO/govtool.git"
HOST_FRONTEND_DIR="./govtool/frontend"
UPDATE=$1

if [ -d ".git" ]; then
echo "Resetting repository to a clean state..."
git reset --hard HEAD
git clean -fd
echo "Pulling latest changes from the current branch..."
git fetch origin
git pull origin $(git rev-parse --abbrev-ref HEAD)
if [ "$UPDATE" == "true" ]; then
echo "Update mode enabled."
else
echo "Error: Repository is not properly cloned. Exiting."
exit 1
echo "Setup mode enabled."
fi

# Navigate to the frontend directory
cd /app/govtool/frontend
clone_and_copy() {
echo "Cloning repository and copying files..."

# Check if node_modules exists and reinstall dependencies without the lock file
if [ ! -d "node_modules" ]; then
mkdir -p "$(dirname "$HOST_FRONTEND_DIR")"

docker run --name clone-govtool --interactive --tty \
--workdir /app \
node:20-alpine sh -c "
apk add --no-cache git && \
if [ ! -d 'govtool' ]; then \
echo 'Cloning repository into container...' ; \
git clone ${REPO_URL} ; \
else \
echo 'Repository already cloned.' ; \
fi"

if docker cp clone-govtool:/app/govtool/govtool/frontend ./govtool/; then
echo "Frontend files copied to host."
cp govtool/frontend/.env.example govtool/frontend/.env
else
echo "Error: Frontend directory not found in container. Verify the repository structure."
docker stop clone-govtool && docker rm -v clone-govtool
exit 1
fi

docker stop clone-govtool && docker rm -v clone-govtool || echo "Container already removed."
}

if [ ! -d "$HOST_FRONTEND_DIR" ] || [ "$UPDATE" = true ]; then
echo "Initial setup or update required..."
clone_and_copy
else
echo "Frontend directory already exists. Skipping clone."
fi

# install node dependencies in the frontend directory
if [ ! -d "$HOST_FRONTEND_DIR/node_modules" ]|| [ "$UPDATE" = true ]; then
echo "Installing dependencies..."
npm install
docker run --rm --interactive --tty \
--volume "${PWD}/govtool/frontend:/app" \
--workdir /app \
--user root \
node:20-alpine yarn install --ignore-engine
else
echo "Dependencies already installed."
fi

# Start the application
echo "Starting the application..."
exec "$@"
# Ensure permissions are set correctly
echo "Adjusting permissions..."
chmod -R 777 "$HOST_FRONTEND_DIR"

echo "Govtool setup completed!"

0 comments on commit 3d4db54

Please sign in to comment.