-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·98 lines (87 loc) · 3.28 KB
/
build
File metadata and controls
executable file
·98 lines (87 loc) · 3.28 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
set -o pipefail -e
replace () {
if [ "$( uname -s )" = "Darwin" ]; then
sed -E -i '' "$1" "$2"
else
sed -E -i "$1" "$2"
fi
}
NAMESPACE="${NAMESPACE:-codycraven}"
LATEST="${LATEST:-0}"
VERSION_REGEX="^([0-9]*)\.([0-9]*)(\.([0-9]+((-|.)[^ ]*)?))$"
if [[ "$1" =~ $VERSION_REGEX ]]; then
PHP_VERSION="$1"
else
>&2 echo -e "\033[1mFailed to build:\033[0m Invalid PHP version supplied\n\n" \
"Example: ./build \033[1m7.1.4\033[0m 7.9.0\n"
exit 1
fi
# Ensure the Docker Hub image exists for the PHP version.
IMAGE_EXISTS=$( curl -s -S "https://registry.hub.docker.com/v2/repositories/library/php/tags/$PHP_VERSION-alpine/" )
if [[ "$IMAGE_EXISTS" =~ "Not found" ]]; then
>&2 echo -e "\033[1mFailed to build:\033[0m PHP version" \
"\033[1m$PHP_VERSION\033[0m not available from https://hub.docker.com/_/php/\n"
exit 1
fi
if [[ "$2" =~ $VERSION_REGEX ]]; then
NODE_VERSION="$2"
else
>&2 echo -e "\033[1mFailed to build:\033[0m Invalid Node version supplied\n\n" \
"Example: ./build 7.1.4 \033[1m7.9.0\033[0m\n"
exit 1
fi
# Ensure fresh builds
rm -fr builds
mkdir -p builds/builder builds/main
# Main image
echo -e "FROM php:$PHP_VERSION-alpine" > builds/main/Dockerfile
# Define versions
YARN_VERSION="$( curl -sSL https://yarnpkg.com/latest-version )"
BUILD_TAG="php-$PHP_VERSION--node-$NODE_VERSION"
# Install Composer
echo -e "\n" >> builds/main/Dockerfile
cat << COMPOSER >> builds/main/Dockerfile
# Composer install
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"; \\
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"; \\
php composer-setup.php --filename=composer --install-dir=/usr/local/bin; \\
php -r "unlink('composer-setup.php');";
COMPOSER
# Install Node based on nodejs/docker-node's alpine template.
echo -e "\n\n# Node $NODE_VERSION install" >> builds/main/Dockerfile
curl -s -S "https://raw.githubusercontent.com/nodejs/docker-node/master/Dockerfile-alpine.template" \
| tail -n +3 \
| cat >> builds/main/Dockerfile
# Set PHP/Node/Yarn versions
replace 's/^(ENV NODE_VERSION ).*/\1'"$NODE_VERSION"'/' builds/main/Dockerfile
replace 's/^(ENV YARN_VERSION ).*/\1'"$YARN_VERSION"'/' builds/main/Dockerfile
# Build
docker build -t "$NAMESPACE/php-node:$BUILD_TAG" builds/main
# Builder image
echo -e "FROM $NAMESPACE/php-node:$BUILD_TAG\n" > builds/builder/Dockerfile
cat << DEPS >> builds/builder/Dockerfile
# Common build dependencies
RUN apk add --no-cache \\
build-base \\
git \\
python
DEPS
# Build
docker build -t "$NAMESPACE/php-node:$BUILD_TAG--builder" builds/builder
# If latest specified, then tag and copy Dockerfiles.
if [ $LATEST -eq 1 ]; then
docker tag \
${NAMESPACE}/php-node:${BUILD_TAG} \
${NAMESPACE}/php-node:latest
docker tag \
${NAMESPACE}/php-node:${BUILD_TAG}--builder \
${NAMESPACE}/php-node:latest--builder
cp builds/main/Dockerfile main/Dockerfile
cp builds/builder/Dockerfile builder/Dockerfile
echo "Tagged latest and updated builds/*, please add/commit and push"
fi
# Update Docker Hub README.md
cp Docker-hub-README.md main/README.md
# Clean up
rm -fr builds