Skip to content

Commit 1318e81

Browse files
committed
Refactor bump script, validate tags. Closes #40
1 parent 1eea447 commit 1318e81

File tree

4 files changed

+69
-97
lines changed

4 files changed

+69
-97
lines changed

bin/bump-wordpress.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
# This script is a part of the ideasonpurpose/docker-wordpress-dev project
4+
# https://github.com/ideasonpurpose/docker-wordpress-dev
5+
#
6+
# Version: 0.9.4
7+
#
8+
# This script does a few things:
9+
#
10+
# 1. Fetch the list of stable WordPress versions from the wordpress.org API
11+
# and extract the latest version number.
12+
# 2. Request that tag from DockerHub to check that the image exists.
13+
#
14+
# If the version has a matching tag on DockerHub:
15+
# - Store the version in wp-version.json. The file is just something like this:
16+
# { "wordpress": "5.9.2" }
17+
# - Update the WordPress base image in the Dockerfile.
18+
# - Update the WordPress version in README.md.
19+
# - Update the WordPress version in the boilerplate-tooling docker-compose files
20+
#
21+
# The wp-version.json file should be commited to Git. The push-to-dockerhub
22+
# GitHub Action uses this file to generate tag names for the Docker Image.
23+
24+
# style helpers
25+
RESET="\033[0m"
26+
BOLD="\033[1m"
27+
RED="\033[31m"
28+
GREEN="\033[32m"
29+
GOLD="\033[33m"
30+
BLUE="\033[34m"
31+
MAGENTA="\033[35m"
32+
CYAN="\033[36m"
33+
34+
echo -e "💫 Fetching releases from the ${CYAN}WordPress API${RESET}..."
35+
wget -q -O- http://api.wordpress.org/core/stable-check/1.0 >/tmp/wp.json
36+
echo -e "👀 Found ${CYAN}$(jq -r 'length' /tmp/wp.json)${RESET} releases"
37+
38+
# jq '{wordpress: (to_entries[] | select(.value == "latest").key)}' /tmp/wp.json >/app/wp-version.json
39+
WP_LATEST=$(jq -r 'to_entries[] | select(.value == "latest").key' /tmp/wp.json)
40+
# WP_LATEST=5.9 # debug: Known good
41+
# WP_LATEST=5.8.111 # debug: Known bad
42+
echo -e "🎁 Latest WordPress release is ${CYAN}${WP_LATEST}${RESET}"
43+
44+
echo -e "🔍 Checking DockerHub to see if ${CYAN}wordpress:${WP_LATEST}${RESET} tag exists..."
45+
wget -q -O- https://registry.hub.docker.com/v2/repositories/library/wordpress/tags/${WP_LATEST}/ >/tmp/dockerhub-check.json
46+
if [[ ! -s /tmp/dockerhub-check.json ]]; then
47+
echo -e "⚠️ ${RED}Tag ${WP_LATEST} not found on DockerHub, unable to bump WordPress version.${RESET}"
48+
exit
49+
fi
50+
echo -e "🎉 It does!"
51+
52+
jq -n "{wordpress: \"${WP_LATEST}\"}" >/app/wp-version.json
53+
echo -e "✏️ Writing $(jq -C -c '.' /app/wp-version.json) to ${GOLD}wp-version.json${RESET}" # shhh, we already wrote it
54+
55+
echo -e "✏️ Updating ${GOLD}Dockerfile${RESET} to ${CYAN}wordpress:${WP_LATEST}${RESET}"
56+
sed -i "s/wordpress:.*-php8/wordpress:${WP_LATEST}-php8/" /app/Dockerfile
57+
58+
echo -e "✏️ Updating ${GOLD}README.md${RESET} to ${CYAN}v${WP_LATEST}${RESET}"
59+
sed -E -i "s/currently\s+\*\*\[v[0-9.]+\]/currently **[v${WP_LATEST}]/" /app/README.md
60+
61+
echo -e "✏️ Updating ${GOLD}docker-compose.yml${RESET} (boilerplate) to ${CYAN}wordpress:${WP_LATEST}${RESET}"
62+
sed -E -i "s/ideasonpurpose\/wordpress:[0-9.]+/ideasonpurpose\/wordpress:${WP_LATEST}/" /app/boilerplate-tooling/docker-compose.yml
63+
64+
echo -e "✅ Done!"

boilerplate-tooling/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ services:
2424
depends_on:
2525
- db
2626
# image: ideasonpurpose/wordpress:dev
27-
image: ideasonpurpose/wordpress:0.9.4
27+
image: ideasonpurpose/wordpress:5.9.1
2828
restart: always
2929
volumes:
3030
- wp_data:/var/www/html

docker-compose.yml

Lines changed: 4 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,11 @@
11
services:
22
# This service bumps the WordPress verion in the Dockerfile to the latest release.
3+
# See the bin/bump-wordpress.sh script for docs
34
#
4-
# The shell script does three things:
5-
#
6-
# 1. Fetch the list of stable WordPress versions from the wordpress.org API
7-
# and store it in wp-version.json. The file is just something like this:
8-
# { "wordpress": "5.9.2" }
9-
# 2. Update the WordPress base image in the Dockerfile.
10-
# 3. Update the WordPress version in README.md.
11-
#
12-
# It also defines a few styling vars and echoes progress.
13-
#
14-
# The wp-version.json file should be commited to Git. The push-to-dockerhub
15-
# GitHub Action uses this file to generate tag names for the Docker Image.
16-
#
17-
# Notes: The jq image runs busybox, so sed uses a different flag for Extended Regex
18-
# Docker images names are not validated, it's possible the image hasn't
19-
# been created yet.
20-
#
21-
# https://hub.docker.com/r/realguess/jq
5+
# https://hub.docker.com/r/jetbrainsinfra/jq
226
bump-wp:
23-
image: realguess/jq:1.4
7+
image: jetbrainsinfra/jq:latest
248
volumes:
259
- ./:/app
2610
command: |
27-
sh -c " RESET=\"\\033[0m\" RED=\"\\033[31m\" GOLD=\"\\033[33m\" CYAN=\"\\033[36m\"
28-
echo -e \"💫 Fetching releases from the $${CYAN}WordPress API$${RESET}.\" &&
29-
wget -q -O- http://api.wordpress.org/core/stable-check/1.0 > /tmp/wp.json &&
30-
echo -e \"👀 Found $${CYAN}$$(jq -r 'length' /tmp/wp.json)$${RESET} releases.\" &&
31-
jq '{wordpress: (to_entries[] | select(.value == \"latest\").key)}' /tmp/wp.json > /app/wp-version.json &&
32-
WP_LATEST=$$(jq -r '.wordpress' /app/wp-version.json) &&
33-
echo -e \"✏️ Updating $${GOLD}Dockerfile$${RESET} to $${CYAN}v$$(jq -r '.wordpress' /app/wp-version.json)$${RESET}.\" &&
34-
sed -i \"s/wordpress:.*-php8/wordpress:$${WP_LATEST}-php8/\" /app/Dockerfile &&
35-
echo -e \"✏️ Updating $${GOLD}README.md$${RESET} to $${CYAN}v$$(jq -r '.wordpress' /app/wp-version.json)$${RESET}.\" &&
36-
sed -r -i \"s/currently\\s+\\*\\*\\[v[0-9.]+\]/currently **[v$$WP_LATEST]/\" /app/README.md
37-
echo -e \"✅ Done!\""
38-
39-
40-
41-
# TODO: Check DockerHub for existance of the latest release beffore continuing?
42-
43-
# https://registry.hub.docker.com/v2/repositories/library/wordpress/tags/5.9.1
44-
45-
# unknown tags return a 404:
46-
47-
# https://registry.hub.docker.com/v2/repositories/library/wordpress/tags/7.9.4
48-
49-
50-
# sed -E -i "s/currently\s+\*\*\[[0-9.]+]/currently **[$WP_LATEST]/" README.md
51-
52-
53-
# https://registry.hub.docker.com/v1/repositories/wordpress/tags
54-
55-
# https://registry.hub.docker.com/v2/repositories/library/wordpress/tags?page_size=100
56-
57-
58-
59-
60-
# cat wp.json| jq 'to_entries[] | select(.value == "latest") | { wordpress: .key, image: (.key + "-v")}' > wp-latest.json
61-
# jq -s '.[0] * (.[1] | {version})' wp-latest.json package.json
62-
# jq -s '.[0] * .[1] | {wordpress, image: (.wordpress + "-v" + .version)}' wp-latest.json package.json
63-
64-
# jq -s '(.[0].to_entries[] | select(.value == "latest")) * .[1]' wp.json package.json
65-
66-
67-
# jq -s '{wordpress: .[0] | to_entries[] | select(.value == "latest").key, version: .[1].version } | {wordpress, image: (.wordpress + "-v" + .version)}' wp.json package.json
68-
# {
69-
# "wordpress": "5.9.2",
70-
# "image": "5.9.2-v0.8.1"
71-
# }
72-
73-
74-
75-
# jq -s '
76-
# {
77-
# wordpress: .[0]
78-
# | to_entries[]
79-
# | select(.value == \"latest\").key,
80-
# version: .[1].version
81-
# } | {
82-
# wordpress,
83-
# image: (.wordpress + \"-v\" + .version)}' \\
84-
# /tmp/wp.json /app/package.json > /app/release.json &&
85-
# WP_LATEST=$$(jq -r '.wordpress' /app/release.json) &&
86-
87-
88-
89-
# 1. Fetch list of stable WordPress versions from the wordpress.org api
90-
# 2. Parse the API result and generate a JSON metadata file in containing
91-
# the latest WordPress version and a full image name from the combined
92-
# WordPress version and the project's version from package.json
93-
# 3. Fetches the latest WordPress release from the JSON file and updates
94-
# the base image in the DockerFile.
95-
#
96-
#
97-
# The generated /tmp/release.json file looks like this:
98-
# {
99-
# "wordpress": "5.9.2",
100-
# "image": "5.9.2-v0.8.1"
101-
# }
102-
11+
sh /app/bin/bump-wordpress.sh

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
"bin/pull.sh",
6666
"bin/wp-init.sh",
6767
"boilerplate-tooling/docker-compose-util.yml",
68-
"boilerplate-tooling/docker-compose.yml",
6968
"Dockerfile",
7069
"README.md"
7170
]

0 commit comments

Comments
 (0)