Skip to content

Commit

Permalink
Prep for seeding
Browse files Browse the repository at this point in the history
  • Loading branch information
timkelty committed Mar 21, 2022
1 parent e2d3a78 commit 372c903
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 29 deletions.
1 change: 0 additions & 1 deletion .env.bref
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ DEFAULT_SITE_URL=http://localhost:8000
CRAFT_STORAGE_PATH=/tmp
CRAFT_EPHEMERAL=1
CRAFT_STREAM_LOG=1

2 changes: 1 addition & 1 deletion .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ DB_USER=craft
DB_PASSWORD=secret
DB_SERVER=postgres
DEFAULT_SITE_URL=http://localhost:${HOST_WEB_PORT}
CRAFT_USE_LOCAL_VOLUMES=1
CRAFT_STREAM_LOG=1
8 changes: 1 addition & 7 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v2

- run: make update
- run: make update_and_reseed

- run: make test

Expand All @@ -44,9 +44,3 @@ jobs:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}

- uses: benc-uk/workflow-dispatch@v1
if: ${{ steps.auto_commit.outputs.changes_detected == 'true' && (github.event.inputs.dockerhub_push || github.event_name == 'schedule') }}
with:
workflow: Build and push docker images
token: ${{ secrets.PAT }}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# use a multi-stage build for dependencies
FROM composer as composer
FROM composer:2 as composer
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN composer install --ignore-platform-reqs --no-interaction --prefer-dist

FROM craftcms/nginx:8.0

USER root
RUN apk add --no-cache postgresql-client
RUN apk add --no-cache postgresql-client git
COPY .docker/default.conf /etc/nginx/conf.d/default.conf
USER www-data

Expand Down
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ EXEC ?= ${COMPOSE} exec -T web
RUN ?= ${COMPOSE} run --rm web
WEB_CONTAINER = docker-compose ps -q web

.PHONY: update restore backup seed test
.PHONY: init update restore backup seed clean test

update:
init:
cp .env.docker .env
${COMPOSE} up -d
make restore
update:
${EXEC} composer update --no-interaction
${EXEC} php craft migrate/all --interactive=0
${EXEC} php craft project-config/apply --force --interactive=0
${EXEC} php craft up --interactive=0
${EXEC} php craft queue/run --interactive=0
${EXEC} php craft gc --delete-all-trashed --interactive=0
make backup
restore:
${EXEC} php craft db/restore ${DUMPFILE}
backup:
Expand All @@ -25,6 +23,9 @@ backup:
docker cp $(shell ${WEB_CONTAINER}):/app/config/project ./config/
seed:
${EXEC} php craft demos/seed
test: seed
clean:
${EXEC} php craft demos/seed/clean
test:
${EXEC} curl -IX GET --fail http://localhost:8080/actions/app/health-check
${EXEC} curl -IX GET --fail http://localhost:8080/
update_and_reseed: init restore clean update seed backup
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ services:
ports:
- "${HOST_WEB_PORT}:8080"
env_file: .env
volumes:
- ./:/app
depends_on:
postgres:
condition: service_healthy
Expand Down
19 changes: 8 additions & 11 deletions modules/demos/src/console/controllers/SeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function actionIndex(): int
public function actionClean(): int
{
$this->runAction('delete-freeform-data');
$this->_cleanup();
return ExitCode::OK;
}

Expand All @@ -68,13 +69,13 @@ public function actionDeleteFreeformData(): int
$i = isset($i) ? $i + 1 : 1;
$this->stdout(" - [{$i}/{$submissionCount}] Deleting submission {$submission->title} ... ");
try {
$success = Craft::$app->getElements()->deleteElement($submission, true);
if ($success) {
$this->stdout('done' . PHP_EOL, Console::FG_GREEN);
} else {
$this->stderr('failed: ' . implode(', ', $submission->getErrorSummary(true)) . PHP_EOL, Console::FG_RED);
$errorCount++;
}
$success = Craft::$app->getElements()->deleteElement($submission, true);
if ($success) {
$this->stdout('done' . PHP_EOL, Console::FG_GREEN);
} else {
$this->stderr('failed: ' . implode(', ', $submission->getErrorSummary(true)) . PHP_EOL, Console::FG_RED);
$errorCount++;
}
} catch (\Throwable $e) {
$this->stderr('error: ' . $e->getMessage() . PHP_EOL, Console::FG_RED);
$errorCount++;
Expand All @@ -100,10 +101,6 @@ private function _cleanup()
$this->stdout('Clearing compiled classes ... ');
FileHelper::removeDirectory($compiledClassesPath);
$this->stdout('done' . PHP_EOL, Console::FG_GREEN);

$this->stdout('Setting system status to online ... ');
Craft::$app->projectConfig->set('system.live', true, null, false);
$this->stdout('done' . PHP_EOL, Console::FG_GREEN);
}

/**
Expand Down

0 comments on commit 372c903

Please sign in to comment.