Skip to content

Commit

Permalink
refactor: favor docker compose in shell scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin-jw committed Oct 31, 2023
1 parent f71091f commit 07c55ec
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ After generating a new repo from the Sparkpress template, you will need to chang
- [ ] `.github/workflows/deploy.docker.yml` (references to the container registry or delete the file if not using a docker deployment process)
- [ ] `.github/workflows/deploy.pantheon.yml` (theme folder names)
- [ ] `.github/workflows/release-please.yml` (`package-name` field)
- [ ] `scripts/export-db.sh` (db container name)
- [ ] `scripts/import-db.sh` (db container names)
- [ ] `src/php/style.css` (theme name plus the other metadata in the file)
- [ ] `src/php/inc/theme-scripts.php` (metadata and prefixes for function/script names)
- [ ] `src/php/inc/theme-setup.php` (metadata and prefixes for function names)
Expand Down
2 changes: 1 addition & 1 deletion scripts/export-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fi
mkdir -p $path

# generate SQL dump
docker exec -i sparkpress_db mysqldump --user=root --password=$MYSQL_ROOT_PASSWORD $MYSQL_DATABASE > $path/$prefix-raw.sql
docker compose exec -i db mysqldump --user=root --password=$MYSQL_ROOT_PASSWORD $MYSQL_DATABASE > $path/$prefix-raw.sql

# replace localhost URLs with target environment URL
sed "s/http:\/\/localhost:8000/$SITE_URL/g" $path/$prefix-raw.sql > $filename
Expand Down
6 changes: 3 additions & 3 deletions scripts/import-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ gunzip sql/db-import-raw.sql.gz
sed "s/$SITE_URL/http:\/\/localhost:8000/g" sql/db-import-raw.sql > sql/db-import.sql

# drop existing database, create a new one, and load it up with data
docker exec -i sparkpress_db mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD -e "drop database if exists $MYSQL_DATABASE"
docker exec -i sparkpress_db mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD -e "create database $MYSQL_DATABASE"
docker exec -i sparkpress_db mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD $MYSQL_DATABASE < sql/db-import.sql
docker compose exec -i db mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD -e "drop database if exists $MYSQL_DATABASE"
docker compose exec -i db mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD -e "create database $MYSQL_DATABASE"
docker compose exec -iT db mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD $MYSQL_DATABASE < sql/db-import.sql

# clean up files that aren't useful after import
rm sql/db-import*
Expand Down
3 changes: 2 additions & 1 deletion scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ if [ "$CI" == "true" ]; then
exec "$@"
else
# Run the command inside the Docker container
docker compose run --rm --no-deps --remove-orphans web "$@"
# use exec if the container's already running, or spin up a temporary container to run it
docker compose exec -it web "$@" || docker compose run --rm --no-deps --remove-orphans web "$@"
fi

0 comments on commit 07c55ec

Please sign in to comment.