From f4ef3f501d8e5e9f4c4472f27fa5793da122060b Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Mon, 6 May 2024 11:03:48 +0530 Subject: [PATCH] feat: CI: test w postgres service --- .woodpecker.yml | 54 ++++++++----------------------------------------- Makefile | 33 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 46 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 6c8dd9c..9bf989b 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -6,12 +6,11 @@ steps: environment: - DATABASE_URL=postgres://postgres:password@database:5432/postgres commands: - - curl -fsSL https://deb.nodesource.com/setup_16.x | bash - &&\ - - apt update && apt-get -y --no-install-recommends install nodejs tar gpg curl wget + # - curl -fsSL https://deb.nodesource.com/setup_16.x | bash - &&\ + # - apt update && apt-get -y --no-install-recommends install nodejs tar gpg curl wget - rustup component add rustfmt - rustup component add clippy - # - make dev-env - # - make migrate + - make db.migrate - make lint - make test - make release @@ -59,45 +58,8 @@ steps: # - scripts/bin-publish.sh publish master latest $DUMBSERVE_PASSWORD # secrets: [RELEASE_BOT_GPG_SIGNING_KEY, DUMBSERVE_PASSWORD, GPG_PASSWORD] # - #services: - # database: - # image: postgres - # environment: - # - POSTGRES_PASSWORD=password - # - # forms-postgres: - # image: postgres - # environment: - # - POSTGRES_PASSWORD=password - # - # librepages-forms: - # image: forgeflux/forgeflux-forms - # command: forms serve - # environment: - # - LPFORMS_SOURCE_CODE=https://git.batsense.net/LibrePages/forms - # - LPFORMS_SERVER__PROXY_HAS_TLS=false - # - LPFORMS_DEBUG=false - # - LPFORMS_SERVER_URL_PREFIX="" - # - LPFORMS_SERVER_DOMAIN=forms.librepages.test - # - LPFORMS_SERVER_IP=0.0.0.0 - # - LPFORMS_SERVER_PROXY_HAS_TLS=false - # - LPFORMS_DASH_API_KEY=longrandomlygeneratedpassword - # - LPFORMS_DATABASE_POOL=2 - # - PORT=6000 - # - DATABASE_URL=postgres://postgres:password@forms-postgres:5432/postgres - # - # librepages-conductor: - # image: forgeflux/forgeflux-conductor - # command: conductor serve - # environment: - # - LPCONDUCTOR_SERVER__PROXY_HAS_TLS=false - # - LPCONDUCTOR_DEBUG=false - # - LPCONDUCTOR_CONDUCTOR=dummy - # - LPCONDUCTOR_SERVER_URL_PREFIX="" - # - LPCONDUCTOR_SERVER_DOMAIN=librepages.test - # - LPCONDUCTOR_SERVER_IP=0.0.0.0 - # - LPCONDUCTOR_SERVER_PROXY_HAS_TLS=false - # - LPCONDUCTOR_SERVER_PORT=7000 - # - LPCONDUCTOR_SOURCE_CODE=https://example.org - # - LPCONDUCTOR_CREDS_TOKEN=longrandomlygeneratedpassword - # - PORT=5000 +services: + database: + image: postgres + environment: + - POSTGRES_PASSWORD=password diff --git a/Makefile b/Makefile index 114e56c..0ebb2d5 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,17 @@ +define deploy_dependencies ## deploy dependencies + @-docker create --name ${db} \ + -e POSTGRES_PASSWORD=password \ + -p 5432:5432 \ + postgres + docker start ${db} +endef + + +define run_migrations ## run database migrations + cd utils/db-migrations/ && unset DATABASE_URL && cargo build + cd utils/db-migrations/ && cargo run +endef + #define cache_bust ## run cache_busting program # npm run sass # cd utils/cache-bust && cargo run @@ -17,6 +31,13 @@ check: ## Check for syntax errors on all workspaces clean: ## Clean all build artifacts and dependencies @cargo clean +db.migrate: ## run migrations + $(call run_migrations) + +db.sqlx.offline: ## prepare sqlx offline data + cargo sqlx prepare \ + --database-url=${DATABASE_URL} -- \ + --all-features #dev-env: ## Download development dependencies # npm install @@ -36,6 +57,18 @@ docker.publish: docker.build ## Build and publish docker images docker push forgeflux/forgeflux:latest docker push forgeflux/forgeflux:0.1.0 + +env.db: ## Deploy dependencies + $(call deploy_dependencies) + sleep 5 + $(call run_migrations) + +env.db.recreate: ## Deploy dependencies from scratch + @-docker rm -f ${db} + $(call deploy_dependencies) + sleep 5 + $(call run_migrations) + lint: ## Lint codebase cargo fmt -v --all -- --emit files cargo clippy --workspace --tests --all-features