-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·49 lines (42 loc) · 1.3 KB
/
build.sh
File metadata and controls
executable file
·49 lines (42 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
set -eo pipefail
APP_NAME=$1
LOCK_FILE_LOCAL=""
LOCK_FILE_NAME=""
UPDATE_CACHE=0
echo "NODE ENV: $NODE_ENV"
echo "BABEL ENV: $BABEL_ENV"
# Build the container image
docker compose -f docker/docker-compose.yml build \
--build-arg NODE_ENV=$NODE_ENV \
--build-arg BABEL_ENV=$BABEL_ENV \
--build-arg FILE_PICKER_API_KEY=$FILE_PICKER_API_KEY \
--build-arg FORCE_DEV=$FORCE_DEV \
$APP_NAME
# Create a throwaway container for copying artifacts
docker create --name app $APP_NAME:latest >/dev/null
# Determine which lockfile to compare (pnpm preferred, fallback to npm)
if [ -f pnpm-lock.yaml ]; then
LOCK_FILE_NAME="pnpm-lock.yaml"
elif [ -f package-lock.json ]; then
LOCK_FILE_NAME="package-lock.json"
fi
if [ -z "$LOCK_FILE_NAME" ] || [ ! -d node_modules ]; then
UPDATE_CACHE=1
else
# Compare lockfile from container with local copy
cp "$LOCK_FILE_NAME" ".old-$LOCK_FILE_NAME"
docker cp "app:/$APP_NAME/$LOCK_FILE_NAME" "$LOCK_FILE_NAME"
set +e
cmp "$LOCK_FILE_NAME" ".old-$LOCK_FILE_NAME" >/dev/null 2>&1
CMP_STATUS=$?
set -e
if [ $CMP_STATUS -ne 0 ]; then
UPDATE_CACHE=1
fi
fi
if [ "$UPDATE_CACHE" -eq 1 ]; then
echo "Lockfile changed or node_modules missing; refreshing local node_modules from container..."
rm -rf node_modules
docker cp "app:/$APP_NAME/node_modules" .
fi