-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·88 lines (78 loc) · 2.48 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·88 lines (78 loc) · 2.48 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
#!/bin/bash
#
# Builds and optionally pushes Docker images for WordPress and WP-CLI.
#
# Usage: ./build.sh [push]
#
# Options:
# push Push images to Docker Hub after building
#
set -eo pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
action=$1
# Extract versions from Dockerfiles using portable grep/sed
WORDPRESS_VERSION=$(grep 'ENV WORDPRESS_VERSION' $DIR/fpm/Dockerfile | sed 's/ENV WORDPRESS_VERSION //')
WPCLI_VERSION=$(grep 'ENV WPCLI_VERSION' $DIR/cli/Dockerfile | sed 's/ENV WPCLI_VERSION //')
if [ -z "$WORDPRESS_VERSION" ]; then
echo "Error: Could not extract WordPress version from fpm/Dockerfile"
exit 1
fi
if [ -z "$WPCLI_VERSION" ]; then
echo "Error: Could not extract WP-CLI version from cli/Dockerfile"
exit 1
fi
echo "WordPress Version: $WORDPRESS_VERSION"
echo "WP-CLI Version: $WPCLI_VERSION"
# Create buildx builder if it doesn't exist
if ! docker buildx inspect wordpress > /dev/null 2>&1; then
echo "Creating buildx builder 'wordpress'..."
docker buildx create --name wordpress --use --bootstrap
else
echo "Using existing buildx builder 'wordpress'..."
docker buildx use wordpress
fi
###
# Build WordPress FPM image
###
echo "Building WordPress FPM image..."
if [[ "push" == "$action" ]]; then
docker buildx build --push \
--platform linux/amd64,linux/arm64 \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from type=registry,ref=joshbetz/wordpress:latest \
-t joshbetz/wordpress:latest \
-t joshbetz/wordpress:$WORDPRESS_VERSION \
$DIR/fpm
else
docker buildx build \
--platform linux/amd64,linux/arm64 \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from type=registry,ref=joshbetz/wordpress:latest \
-t joshbetz/wordpress:latest \
-t joshbetz/wordpress:$WORDPRESS_VERSION \
$DIR/fpm
fi
###
# Build WP-CLI image
###
echo "Building WP-CLI image..."
if [[ "push" == "$action" ]]; then
docker buildx build --push \
--platform linux/amd64,linux/arm64 \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from type=registry,ref=joshbetz/wordpress:cli \
-t joshbetz/wordpress:cli \
-t joshbetz/wordpress:$WORDPRESS_VERSION-cli \
-t joshbetz/wordpress:$WORDPRESS_VERSION-cli-$WPCLI_VERSION \
$DIR/cli
else
docker buildx build \
--platform linux/amd64,linux/arm64 \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from type=registry,ref=joshbetz/wordpress:cli \
-t joshbetz/wordpress:cli \
-t joshbetz/wordpress:$WORDPRESS_VERSION-cli \
-t joshbetz/wordpress:$WORDPRESS_VERSION-cli-$WPCLI_VERSION \
$DIR/cli
fi
echo "Build complete."