Skip to content

Commit 3841a06

Browse files
committed
Restrict syncing of uploads. Closes #20
1 parent 35cfad9 commit 3841a06

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,18 @@ Copy your MySQL database dumpfiles into before calling Calling `npm run start` w
9393
Syncs data from a remote server to the local development environment. The bare command will run these sub-commands:
9494
- **`pull:db`** - Syncs down the most recent mySQL dumpfile, backs up the current dev DB then reloads the DB
9595
- **`pull:plugins`** - Syncs down **wp-content/plugins** from the remote
96-
- **`pull:uploads`** - Syncs down **wp-content/uploads** from the remote
96+
- **`pull:uploads <$YEAR>`** - Syncs down the current year's **wp-content/uploads/$YEAR** from the remote. Sync specific years with the optional year argument.
97+
- **`pull:uploads-all`** - Syncs down the entire **wp-content/uploads** directory from the remote
9798
- **`logs:wordpress`** - Stream the WordPress debug.log
9899
- **`wp-cli`** - Runs [wp-cli](https://wp-cli.org/vc) commands. The default command re-activates the development theme.
99100

100101
### Pulling Data from Remote Servers
101102

102103
The `npm run pull` command brings together several sub-commands to sync remote data to the local development environment. Each command can also be called individually. Connection info needs to be configured in a **.env** file. Values are documented in the **.env.sample** file.
103104

104-
Private SSH keys are passed to the image as [Docker Secrets][], set `$SSH_KEY_PATH to a local keypath in **.env**.
105+
Private SSH keys are passed to the image as [Docker Secrets][docker-secrets], point `$SSH_KEY_PATH` to a local private key in **.env**.
105106

106-
Pulling uploads, plugins and database dumps is currently supported on WP Engine.
107+
Pulling uploads, plugins and database dumps is currently supported on WP Engine and Kinsta.
107108

108109
Connections must be configured on a per-machine basis using a `.env` file in the project root. For new projects, rename the `.env.example` to **.env** and update the settings.
109110

@@ -160,7 +161,7 @@ docker-compose -f docker-compose.yml -f docker-compose-util.yml run --rm compos
160161

161162
### Alternate DevServer Ports
162163

163-
_note: This no longer works for npm versions > v7. See [#29](https://github.com/ideasonpurpose/docker-wordpress-dev/issues/29)_
164+
_note: This no longer works for npm versions >v6. See [#29](https://github.com/ideasonpurpose/docker-wordpress-dev/issues/29)_
164165

165166
Webpack devserver runs on port `8080` by default. Multiple projects can be run simultaneously by using `npm config` to assign different ports the the project's **package.json** `name`. For example, three projects named `csr-site`, `pro-bono` and `ar-project` could be run simultaneously on custom ports, after running these commands:
166167

@@ -200,7 +201,7 @@ This project's Dockerfile is based on the official WordPress image. We add [Xdeb
200201
All shell scripts in **bin** have been checked with [ShellCheck](https://www.shellcheck.net/) and formatted with [shfmt](https://github.com/mvdan/sh) via Docker:
201202

202203
```sh
203-
docker run --rm -it -v "$PWD":/src peterdavehello/shfmt:latest shfmt -i 2 -w /src/bin/<FILE>.sh
204+
docker run --user "$UID" --rm -it -v "$PWD":/scripts peterdavehello/shfmt:latest shfmt -i 2 -w /scripts/bin/<FILE>.sh
204205
```
205206

206207
## Docker maintenance

bin/pull.sh

100644100755
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,31 @@ fi
138138

139139
#
140140
# Sync down the remote wp-content/uploads directory
141+
# If second arg is "all" then download everything
142+
# If second arg is a year-ish four-digit number then treat as a year and download that year
143+
# If second arg is anything else or missing, then download the current year
141144
#
142145
if [[ "$1" == uploads ]]; then
146+
DIR="$(date +%Y)"
147+
LABEL="${DIR}"
148+
149+
if [[ "$2" =~ ^[0-9]{4}$ ]]; then
150+
DIR="${2}"
151+
LABEL="$2"
152+
fi
153+
154+
DIR="${DIR}/"
155+
156+
if [[ "$2" == "all" ]]; then
157+
DIR=""
158+
LABEL="$2"
159+
fi
160+
143161
echo
144-
echo -e "🖼 ${GOLD}Pulling uploads from remote.${RESET}"
162+
echo -e "🖼 ${GOLD}Pulling ${LABEL} uploads from remote.${RESET}"
145163
echo
146-
mkdir -p /usr/src/site/wp-content/uploads
147-
rsync -azhv -e "ssh -p $_PORT" "${_USER}@${_HOST}:${_WP_CONTENT}/uploads/" /usr/src/site/wp-content/uploads/
164+
mkdir -p "/usr/src/site/wp-content/uploads/${DIR}"
165+
rsync -azhv -e "ssh -p $_PORT" "${_USER}@${_HOST}:${_WP_CONTENT}/uploads/${DIR}" "/usr/src/site/wp-content/uploads/${DIR}"
148166
chown -R "${OWNER_GROUP}" /usr/src/site/wp-content/uploads
149167
chmod -R g+w /usr/src/site/wp-content/uploads
150168
fi

src/boilerplate-package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"postpull:db": "npm run mysql:reload",
3838
"pull:plugins": "docker-compose -f docker-compose.yml -f docker-compose-util.yml run --rm pull plugins",
3939
"pull:uploads": "docker-compose -f docker-compose.yml -f docker-compose-util.yml run --rm pull uploads",
40+
"pull:uploads-all": "docker-compose -f docker-compose.yml -f docker-compose-util.yml run --rm pull uploads all",
4041
"start": "npm run docker:start",
4142
"poststart": "npm run stop",
4243
"start:debug": "cross-env-shell \"docker-compose run --rm -p $npm_package_config_port:8080 -p 9229:9229 tools start:debug\"",

0 commit comments

Comments
 (0)