From aeb97a30d8739cb5afc2971fb757babbbcf557b3 Mon Sep 17 00:00:00 2001 From: Jordan Knott Date: Mon, 13 Sep 2021 11:23:09 -0500 Subject: [PATCH] refactor: add docker testing targets to magefile --- docker-compose.dev.yml | 2 +- magefile.go | 20 +++++++++++++++++-- testing/docker-compose.dev.yml | 26 ++++++++++++++++++++++++ testing/docker-compose.latest.yml | 33 +++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 testing/docker-compose.dev.yml create mode 100644 testing/docker-compose.latest.yml diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 8b19b98..8c6a9f0 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -12,7 +12,7 @@ services: volumes: - taskcafe-postgres:/var/lib/postgresql/data ports: - - 8855:5432 + - 8865:5432 mailhog: image: mailhog/mailhog:latest restart: always diff --git a/magefile.go b/magefile.go index bda4469..14ad331 100644 --- a/magefile.go +++ b/magefile.go @@ -98,8 +98,10 @@ func (Backend) GenFrontend() error { } func flagEnv() map[string]string { - hash, _ := sh.Output("git", "rev-parse", "--short", "HEAD") - fmt.Println("[ignore] fatal: no tag matches") + hash, err := sh.Output("git", "rev-parse", "--short", "HEAD") + if err != nil { + fmt.Println("[ignore] fatal: no tag matches") + } tag, err := sh.Output("git", "describe", "--exact-match", "--tags") if err != nil { tag = "nightly" @@ -160,6 +162,20 @@ func Build() { mg.SerialDeps(Frontend.Build, Backend.GenMigrations, Backend.GenFrontend, Backend.Build) } +// Latest is namespace for commands interacting with docker test setups +type Latest mg.Namespace + +func (Latest) Up() error { + return sh.RunV("docker-compose", "-p", "taskcafe-latest", "-f", "testing/docker-compose.latest.yml", "up") +} + +// Test is namespace for commands interacting with docker test setups +type Dev mg.Namespace + +func (Dev) Up() error { + return sh.RunV("docker-compose", "-p", "taskcafe-dev", "-f", "testing/docker-compose.dev.yml", "up") +} + // Docker is namespace for commands interacting with docker type Docker mg.Namespace diff --git a/testing/docker-compose.dev.yml b/testing/docker-compose.dev.yml new file mode 100644 index 0000000..4bb1472 --- /dev/null +++ b/testing/docker-compose.dev.yml @@ -0,0 +1,26 @@ +version: "3" +services: + web: + build: ../ + ports: + - "6677:3333" + depends_on: + - postgres + networks: + - taskcafe-dev-test + environment: + TASKCAFE_DATABASE_HOST: postgres + TASKCAFE_MIGRATE: "true" + postgres: + image: postgres:12.3-alpine + restart: always + networks: + - taskcafe-dev-test + environment: + POSTGRES_USER: taskcafe + POSTGRES_PASSWORD: taskcafe_test + POSTGRES_DB: taskcafe + +networks: + taskcafe-dev-test: + driver: bridge diff --git a/testing/docker-compose.latest.yml b/testing/docker-compose.latest.yml new file mode 100644 index 0000000..a9bd5be --- /dev/null +++ b/testing/docker-compose.latest.yml @@ -0,0 +1,33 @@ +version: "3" +services: + web: + image: taskcafe/taskcafe:latest + # build: . + ports: + - "6688:3333" + depends_on: + - postgres + networks: + - taskcafe-latest-test + environment: + TASKCAFE_DATABASE_HOST: postgres + TASKCAFE_MIGRATE: "true" + postgres: + image: postgres:12.3-alpine + restart: always + networks: + - taskcafe-latest-test + environment: + POSTGRES_USER: taskcafe + POSTGRES_PASSWORD: taskcafe_test + POSTGRES_DB: taskcafe + volumes: + - taskcafe-latest-postgres:/var/lib/postgresql/data + +volumes: + taskcafe-latest-postgres: + external: false + +networks: + taskcafe-latest-test: + driver: bridge