|
1 | 1 | #!/bin/bash |
2 | | -set -ex |
| 2 | +set -e |
| 3 | + |
| 4 | +# Function to handle errors |
| 5 | +error_handler() { |
| 6 | + echo "❌ Error occurred in line $1" |
| 7 | + exit 1 |
| 8 | +} |
| 9 | + |
| 10 | +# Set error handler |
| 11 | +trap 'error_handler $LINENO' ERR |
3 | 12 |
|
4 | 13 | # Convenience workspace directory for later use |
5 | 14 | WORKSPACE_DIR=$(pwd) |
6 | 15 | CHEFS_LOCAL_DIR=${WORKSPACE_DIR}/.devcontainer/chefs_local |
| 16 | +# Note: Global npm packages (knex, jest, dotenv-cli) are now installed in Dockerfile |
| 17 | + |
| 18 | +# Ensure we're in the workspace root |
| 19 | +cd ${WORKSPACE_DIR} |
| 20 | +echo "📍 Working directory: $(pwd)" |
| 21 | + |
| 22 | +# Check if Docker is available |
| 23 | +if ! command -v docker &> /dev/null; then |
| 24 | + echo "❌ Error: Docker is not available" |
| 25 | + exit 1 |
| 26 | +fi |
| 27 | + |
| 28 | +# Check if Docker Compose is available |
| 29 | +if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then |
| 30 | + echo "❌ Error: Docker Compose is not available" |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | + |
| 34 | +# Check if required directories exist |
| 35 | +if [ ! -d "components" ]; then |
| 36 | + echo "❌ Error: components directory not found" |
| 37 | + exit 1 |
| 38 | +fi |
| 39 | + |
| 40 | +if [ ! -d "app" ]; then |
| 41 | + echo "❌ Error: app directory not found" |
| 42 | + exit 1 |
| 43 | +fi |
| 44 | + |
| 45 | +if [ ! -d "app/frontend" ]; then |
| 46 | + echo "❌ Error: app/frontend directory not found" |
| 47 | + exit 1 |
| 48 | +fi |
| 49 | + |
| 50 | +# install dependencies in parallel for faster setup |
| 51 | +echo "📦 Installing dependencies in parallel..." |
7 | 52 |
|
8 | | -npm install knex -g |
9 | | -npm install jest -g |
10 | | -npm install dotenv-cli -g |
| 53 | +# Install components dependencies |
| 54 | +(cd components && npm install) & |
| 55 | +COMPONENTS_PID=$! |
11 | 56 |
|
12 | | -# install components/formio libraries, prepare for ux development and debugging... |
13 | | -cd components |
14 | | -npm install |
| 57 | +# Install app dependencies |
| 58 | +(cd app && npm install) & |
| 59 | +APP_PID=$! |
15 | 60 |
|
16 | | - # install app libraries, prepare for app development and debugging... |
17 | | -cd ../app |
18 | | -npm install |
| 61 | +# Install frontend dependencies |
| 62 | +(cd app/frontend && npm install) & |
| 63 | +FRONTEND_PID=$! |
19 | 64 |
|
20 | | -# install frontend libraries, prepare for ux development and debugging... |
21 | | -cd frontend |
22 | | -npm install |
| 65 | +# Wait for all installations to complete |
| 66 | +wait $COMPONENTS_PID $APP_PID $FRONTEND_PID |
| 67 | + |
| 68 | +# Check if any installations failed |
| 69 | +if [ $? -ne 0 ]; then |
| 70 | + echo "❌ Error: One or more npm installations failed" |
| 71 | + exit 1 |
| 72 | +fi |
| 73 | + |
| 74 | +echo "✅ All dependencies installed successfully!" |
23 | 75 |
|
24 | 76 | # make an initial build of formio components and ready them for frontend |
| 77 | +cd ${WORKSPACE_DIR}/app/frontend |
25 | 78 | npm run build:formio |
26 | 79 | npm run deploy:formio |
27 | 80 |
|
28 | 81 | # copy over the sample files to the image... |
29 | | -cp -u ${CHEFS_LOCAL_DIR}/local.sample.json ${CHEFS_LOCAL_DIR}/local.json |
| 82 | +if [ ! -f "${CHEFS_LOCAL_DIR}/local.json" ]; then |
| 83 | + cp ${CHEFS_LOCAL_DIR}/local.sample.json ${CHEFS_LOCAL_DIR}/local.json |
| 84 | +fi |
30 | 85 |
|
31 | 86 | # fire up postgres... we want to seed the db |
32 | | -docker compose -f ${CHEFS_LOCAL_DIR}/docker-compose.yml up --wait |
| 87 | +echo "🐘 Starting PostgreSQL..." |
| 88 | +if ! docker compose -f ${CHEFS_LOCAL_DIR}/docker-compose.yml up postgres -d; then |
| 89 | + echo "❌ Failed to start PostgreSQL" |
| 90 | + exit 1 |
| 91 | +fi |
| 92 | + |
| 93 | +# Wait for PostgreSQL to be ready |
| 94 | +echo "⏳ Waiting for PostgreSQL to be ready..." |
| 95 | +max_attempts=30 |
| 96 | +attempt=1 |
| 97 | +while [ $attempt -le $max_attempts ]; do |
| 98 | + if docker compose -f ${CHEFS_LOCAL_DIR}/docker-compose.yml exec -T postgres pg_isready -U app -d chefs > /dev/null 2>&1; then |
| 99 | + echo "✅ PostgreSQL is ready!" |
| 100 | + break |
| 101 | + fi |
| 102 | + echo "⏳ Attempt $attempt/$max_attempts: PostgreSQL not ready yet..." |
| 103 | + sleep 2 |
| 104 | + attempt=$((attempt + 1)) |
| 105 | +done |
| 106 | + |
| 107 | +if [ $attempt -gt $max_attempts ]; then |
| 108 | + echo "❌ PostgreSQL failed to start within expected time" |
| 109 | + exit 1 |
| 110 | +fi |
| 111 | + |
33 | 112 | # run an initial migration for the db and seed it... |
34 | 113 | export NODE_CONFIG_DIR=${CHEFS_LOCAL_DIR} # need this to connect to the running postgres instance. |
35 | | -cd .. # back to app dir |
36 | | -npm run migrate |
| 114 | +cd ${WORKSPACE_DIR}/app # ensure we're in the app directory |
| 115 | +echo "🗄️ Running database migrations..." |
| 116 | +if ! npm run migrate; then |
| 117 | + echo "❌ Failed to run database migrations" |
| 118 | + exit 1 |
| 119 | +fi |
37 | 120 | # npm run seed:run |
38 | 121 |
|
39 | | -# install cypress libraries |
40 | | -cd ../tests/functional/cypress |
41 | | -npm ci |
42 | | - |
43 | 122 | # take down postgres, do not need them running all the time. |
44 | | -docker compose -f ${CHEFS_LOCAL_DIR}/docker-compose.yml down |
| 123 | +echo "🛑 Stopping PostgreSQL..." |
| 124 | +if ! docker compose -f ${CHEFS_LOCAL_DIR}/docker-compose.yml down; then |
| 125 | + echo "⚠️ Warning: Failed to stop PostgreSQL containers" |
| 126 | +fi |
| 127 | + |
| 128 | +# Note: Cypress installation is now handled via VS Code tasks |
| 129 | +# Run Task -> Install Cypress |
| 130 | +# Run Task -> Run Cypress Tests (Interactive) |
| 131 | + |
0 commit comments