-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
78 lines (59 loc) · 2 KB
/
start.sh
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
CHECKSUM_FILE=".dockerfile_checksum"
IMAGE_NAME="api-skeleton/php:latest"
NEW_CHECKSUM=$(sha256sum Dockerfile | cut -d " " -f 1)
if [ -f $CHECKSUM_FILE ]; then
OLD_CHECKSUM=$(cat $CHECKSUM_FILE)
else
OLD_CHECKSUM=""
fi
if [ "$NEW_CHECKSUM" != "$OLD_CHECKSUM" ]; then
echo "Dockerfile has changed. Removing old image."
echo $NEW_CHECKSUM >$CHECKSUM_FILE
docker image rm -f $IMAGE_NAME >/dev/null 2>&1
fi
IMAGE_EXISTS=$(docker images -q $IMAGE_NAME)
if [ -z "$IMAGE_EXISTS" ]; then
echo "Image does not exist. Building image."
docker build -t $IMAGE_NAME .
else
echo "Image exists. Using existing image."
fi
docker rm -f php >/dev/null 2>&1
docker run -d --name php \
--user "$(id -u):$(id -g)" \
-v $(pwd):/app \
-w /app \
$IMAGE_NAME bash -c "tail -f /dev/null"
echo -e "Container started.";
vendorExists=false
if [ ! -d vendor ]; then
echo -e "Directory \033[34;1mvendor\033[0m doesn't exist. Installing dependencies."
docker exec php composer install
echo "Dependencies installed."
else
vendorExists=true
fi
docker exec php composer create-project pbaszak/skeleton --no-interaction
rm -rf skeleton/src
cp -r src/src skeleton/src
cp -r src/tests skeleton/tests
docker exec php php scripts/Setup.php
docker stop php >/dev/null 2>&1
docker rm -f php >/dev/null 2>&1
docker rmi -f $IMAGE_NAME >/dev/null 2>&1
# ApiDoc Bundle
cp src/config/routes/nelmio_api_doc.yaml skeleton/config/routes/nelmio_api_doc.yaml
cp src/config/packages/nelmio_api_doc.yaml skeleton/config/packages/nelmio_api_doc.yaml
rm -rf node_modules scripts src .gitignore CHANGELOG.md composer.json composer.lock README.md LICENSE vendor start.sh package.json package-lock.json Dockerfile
rm -rf skeleton/.github
mv skeleton/{,.[^.]}* ./
rm -rf skeleton
rm -rf CHANGELOG.md
bash start.sh
rm -rf .git
# setup github auth if GITHUB_TOKEN env exists
if [ -n "$GITHUB_TOKEN" ]; then
docker exec php composer config -g github-oauth.github.com $GITHUB_TOKEN
fi
docker exec php composer update