Skip to content

Commit dca4025

Browse files
committed
feat: implement import and export scripts for Docker volumes + fix healthchecks
1 parent d62679b commit dca4025

File tree

5 files changed

+35
-38
lines changed

5 files changed

+35
-38
lines changed

apps/export-src.sh

Lines changed: 0 additions & 25 deletions
This file was deleted.

apps/import-srv.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
service="php" # service name in docker-compose.yml
5+
6+
# Find the container ID for this project, even if it is stopped
7+
cid=$(docker compose ps -a -q "$service")
8+
9+
if [ -z "$cid" ]; then
10+
echo "No '$service' container found for this project (running or stopped)."
11+
exit 1
12+
fi
13+
14+
# Ask Docker for the project name via the container label
15+
project=$(docker inspect -f '{{ index .Config.Labels "com.docker.compose.project" }}' "$cid")
16+
17+
# Compose the volume name: <project>_wordpress-src
18+
volume="${project}_wordpress-src"
19+
20+
echo "Using container ID: $cid"
21+
echo "Using volume: $volume"
22+
23+
# Copy everything from ./srv into /var/www/html inside the volume
24+
docker run --rm \
25+
-v "${volume}:/var/www/html" \
26+
-v "$(pwd)/srv:/srv" \
27+
alpine sh -c 'cp -r /srv/* /var/www/html/ && ls -la /var/www/html/'

apps/init/healthcheck.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/bash
22

3-
if cgi-fcgi -bind -connect 127.0.0.1:9000 > /dev/null 2>&1; then
4-
echo "php-fpm is healthy"
5-
exit 0
6-
else
7-
echo "php-fpm is not healthy"
8-
exit 1
9-
fi
3+
4+
>/dev/tcp/127.0.0.1/9000 && exit 0 || exit 1

docs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ DOCKER_WORDPRESS_SRC_PATH=./srv
114114
You can export the source files of the current wordpress installation inside the /srv folder (backup) with the following command:
115115

116116
```bash
117-
npm run docker:src:export
117+
npm run docker:srv:export
118118
```
119119

120120
#### Import source files
121121

122-
You can import the source files under /srv folder inside the /var/www/html container folder(restore backup) with the following command:
122+
You can import the source files under /srv/ folder inside the /var/www/html container folder(restore backup) with the following command:
123123

124124
```bash
125-
npm run docker:src:import
125+
npm run docker:srv:import
126126
```
127127

128128
IMPORTANT: this command needs to be executed with a bash-compatible shell and it will stop the php running container. After the import is done, you can start the container again.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"docker:logs": "docker compose logs --tail=200 --follow",
2828
"docker:db:export": "docker compose up -d wp-db && docker compose exec wp-db /apps/db_exporter/db_export.sh",
2929
"docker:db:import": "docker compose up -d wp-db && docker compose exec wp-db /apps/db_exporter/db_import.sh",
30-
"docker:src:export": "docker compose cp php:/var/www/html srv",
31-
"docker:src:import": "bash apps/export-src.sh"
30+
"docker:srv:export": "docker compose cp php:/var/www/html/* srv",
31+
"docker:srv:import": "bash apps/import-srv.sh"
3232
},
3333
"devDependencies": {
3434
"@types/node": "^14.0.13"

0 commit comments

Comments
 (0)