Skip to content

Instantly share code, notes, and snippets.

@fachryansyah
Created December 9, 2019 03:47
Show Gist options
  • Save fachryansyah/529c34d26076eeeada2f47e919b3136b to your computer and use it in GitHub Desktop.
Save fachryansyah/529c34d26076eeeada2f47e919b3136b to your computer and use it in GitHub Desktop.
DIR=deployments/docker
RECIPE=${DIR}/docker-compose.yaml
NAMESPACE=builder${COMPONENT}
MIGRATION_PATH=`pwd`/migrations/test
include .env
export $(shell sed 's/=.*//' .env)
DIND_PREFIX ?= $(HOME)
ifneq ($(HOST_PATH),)
DIND_PREFIX := $(HOST_PATH)
endif
ifeq ($(CACHE_PREFIX),)
CACHE_PREFIX=/tmp
endif
PREFIX=$(shell echo $(PWD) | sed -e s:$(HOME):$(DIND_PREFIX):)
UID=$(shell whoami)
IMAGE_TAG ?= master
export $IMAGE_TAG
.PHONY : test
quicktest:
docker-compose -f ${RECIPE} -p ${NAMESPACE} run dailyworker-clear-staging-data
docker run \
--network ${NAMESPACE}_default \
--env-file .env \
-v $(CACHE_PREFIX)/cache/go:/go/pkg/mod \
-v $(CACHE_PREFIX)/cache/apk:/etc/apk/cache \
-v $(PREFIX)/deployments/docker/build:/build \
-v $(PREFIX)/:/src \
-v /tmp:/tmp \
-v $(PREFIX)/deployments/docker/api/fonts:/usr/share/fonts \
-v $(PREFIX)/templates:/templates \
-v $(PREFIX)/migrations:/migrations \
-v $(PREFIX)/scripts/test.sh:/test.sh \
-e UID=$(UID) \
docker.brilife.citradigital.dev/core/simply-test-base /test.sh
# make infratest
dailyworker_image_clear_staging_data:
docker-compose -f ${RECIPE} -p ${NAMESPACE} build --no-cache dailyworker-clear-staging-data
test: infratest
docker run \
--network ${NAMESPACE}_default \
--env-file .env \
-v $(CACHE_PREFIX)/cache/go:/go/pkg/mod \
-v $(CACHE_PREFIX)/cache/apk:/etc/apk/cache \
-v $(PREFIX)/deployments/docker/build:/build \
-v $(PREFIX)/:/src \
-v $(PREFIX)/deployments/docker/api/fonts:/usr/share/fonts \
-v $(PREFIX)/templates:/templates \
-v $(PREFIX)/migrations:/migrations \
-v $(PREFIX)/scripts/test.sh:/test.sh \
-e UID=$(UID) \
golang:1.12-alpine /test.sh
deps:
@./scripts/deps.sh
cleantest:
docker-compose -f ${RECIPE} -p ${NAMESPACE} stop
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testdb
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testredis
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testnats
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testsmtp
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testkirimsurel
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testblob
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testminio
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testbriva
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testcustomers
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testvouchers
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testorders
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testsmsblast
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testhalodoc
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testsshd
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f testtime
docker network remove ${NAMESPACE}_default ; /bin/true
migrate:
docker run --network buildersimply_default -v `pwd`/migrations/deploy:/migrations migrate/migrate -source file://migrations -database 'postgres://${DB_USER}:${DB_PASS}@testdb:5432/testdb?sslmode=disable' drop
docker run --network buildersimply_default -v `pwd`/migrations/deploy:/migrations migrate/migrate -source file://migrations -database 'postgres://${DB_USER}:${DB_PASS}@testdb:5432/testdb?sslmode=disable' up
migrate-local:
docker run --network buildersimply_default -v `pwd`/migrations/deploy:/migrations migrate/migrate -source file://migrations -database 'postgres://${DB_USER}:${DB_PASS}@testdb-local:5432/testdb?sslmode=disable' drop
docker run --network buildersimply_default -v `pwd`/migrations/deploy:/migrations migrate/migrate -source file://migrations -database 'postgres://${DB_USER}:${DB_PASS}@testdb-local:5432/testdb?sslmode=disable' up
infratest: dailyworker_image_clear_staging_data
docker network create -d bridge ${NAMESPACE}_default ; /bin/true
docker-compose -f ${RECIPE} -p ${NAMESPACE} pull
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testdb
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testnats
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testredis
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testsmtp
docker-compose -f ${RECIPE} -p ${NAMESPACE} run testdb createdb -h ${DB_HOST} -U ${DB_USER} -w ${DB_NAME}kirimsurel
docker-compose -f ${RECIPE} -p ${NAMESPACE} up --force-recreate testkirimsurelmigrate
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testkirimsurel
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testkirimsurelworker
docker-compose -f ${RECIPE} -p ${NAMESPACE} run testdb createdb -h ${DB_HOST} -U ${DB_USER} -w ${DB_NAME}blob
docker-compose -f ${RECIPE} -p ${NAMESPACE} up --force-recreate testblobmigrate
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testblob
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testminio
docker-compose -f ${RECIPE} -p ${NAMESPACE} run testdb createdb -h ${DB_HOST} -U ${DB_USER} -w ${DB_NAME}vouchers
docker-compose -f ${RECIPE} -p ${NAMESPACE} up --force-recreate testvouchersmigrate
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testvouchers
docker-compose -f ${RECIPE} -p ${NAMESPACE} run testdb createdb -h ${DB_HOST} -U ${DB_USER} -w ${DB_NAME}customers
docker-compose -f ${RECIPE} -p ${NAMESPACE} up --force-recreate testcustomersmigrate
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testcustomers
docker-compose -f ${RECIPE} -p ${NAMESPACE} run testdb createdb -h ${DB_HOST} -U ${DB_USER} -w ${DB_NAME}customerauth
docker-compose -f ${RECIPE} -p ${NAMESPACE} up --force-recreate testcustomerauthmigrate
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testcustomerauth
docker-compose -f ${RECIPE} -p ${NAMESPACE} run testdb createdb -h ${DB_HOST} -U ${DB_USER} -w ${DB_NAME}orders
docker-compose -f ${RECIPE} -p ${NAMESPACE} up --force-recreate testordersmigrate
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testorders
docker-compose -f ${RECIPE} -p ${NAMESPACE} run testdb createdb -h ${DB_HOST} -U ${DB_USER} -w ${DB_NAME}smsblast
docker-compose -f ${RECIPE} -p ${NAMESPACE} up --force-recreate testsmsblastmigrate
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testsmsblast
docker-compose -f ${RECIPE} -p ${NAMESPACE} run testdb createdb -h ${DB_HOST} -U ${DB_USER} -w ${DB_NAME}halodoc
docker-compose -f ${RECIPE} -p ${NAMESPACE} up --force-recreate testhalodocmigrate
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testhalodoc
docker-compose -f ${RECIPE} -p ${NAMESPACE} run testdb createdb -h ${DB_HOST} -U ${DB_USER} -w ${DB_NAME}channels
docker-compose -f ${RECIPE} -p ${NAMESPACE} up --force-recreate testchannelmigrate
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testchannels
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testbriva
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testsshd
docker-compose -f ${RECIPE} -p ${NAMESPACE} up -d --force-recreate testtime
pollingworker:
docker run -v $(CACHE_PREFIX)/cache/go:/go/pkg/mod \
-v $(CACHE_PREFIX)/cache/apk:/etc/apk/cache \
-v $(PREFIX)/deployments/docker/build:/build \
-v $(PREFIX)/scripts/build.worker.sh:/build.sh \
-v $(PREFIX)/:/src \
-v $(PREFIX)/cmd:/src/cmd \
-e RUNNER_USER \
docker.brilife.citradigital.dev/core/module-builder /build.sh pollingworker
dailyworker:
docker run -v $(CACHE_PREFIX)/cache/go:/go/pkg/mod \
-v $(CACHE_PREFIX)/cache/apk:/etc/apk/cache \
-v $(PREFIX)/deployments/docker/build:/build \
-v $(PREFIX)/scripts/build.worker.sh:/build.sh \
-v $(PREFIX)/:/src \
-v $(PREFIX)/cmd:/src/cmd \
-e RUNNER_USER \
docker.brilife.citradigital.dev/core/module-builder /build.sh dailyworker
buildapi: dailyworker pollingworker
docker run -v $(CACHE_PREFIX)/cache/go:/go/pkg/mod \
-v $(CACHE_PREFIX)/cache/apk:/etc/apk/cache \
-v $(PREFIX)/deployments/docker/build:/build \
-v $(PREFIX)/scripts/build.sh:/build.sh \
-v $(PREFIX)/:/src \
-v $(PREFIX)/cmd:/src/cmd \
-e RUNNER_USER \
docker.brilife.citradigital.dev/core/module-builder /build.sh ${COMPONENT}
runapi: buildapi
docker run --network ${NAMESPACE}_default -p 8000:8000 --env-file .env -v `pwd`/templates:/templates \
-v `pwd`/deployments/docker/build/api:/api alpine /api
runpollingworker:
docker run --network builderorkal_default --env-file .env -v `pwd`/deployments/docker/build/pollingworker:/pollingworker alpine /pollingworker
buildgrpc:
docker run -v $(CACHE_PREFIX)/cache/go:/go/pkg/mod \
-v $(CACHE_PREFIX)/cache/apk:/etc/apk/cache \
-v $(PREFIX)/deployments/docker/build:/build \
-v $(PREFIX)/scripts/build.grpc.sh:/build.sh \
-v $(PREFIX)/:/src \
-v $(PREFIX)/cmd:/src/cmd \
docker.brilife.citradigital.dev/core/module-builder /build.sh
rungrpc: buildgrpc
docker run --network ${NAMESPACE}_default --env-file .env -v `pwd`/deployments/docker/build/grpc:/grpc alpine /grpc
cleangrpc:
docker-compose -f ${RECIPE} -p ${NAMESPACE} stop
docker-compose -f ${RECIPE} -p ${NAMESPACE} rm -f grpc
build_migrate:
docker-compose -f ${RECIPE} -p ${NAMESPACE} build --no-cache migrate
worker_image:
docker-compose -f ${RECIPE} -p ${NAMESPACE} build --no-cache pollingworker
docker-compose -f ${RECIPE} -p ${NAMESPACE} build --no-cache dailyworker
api: buildapi build_migrate
docker-compose -f ${RECIPE} -p ${NAMESPACE} build --no-cache api
grpc: cleangrpc buildgrpc
docker-compose -f ${RECIPE} -p ${NAMESPACE} build --no-cache grpc
refresh:
docker-compose -f ${RECIPE} -p ${NAMESPACE} pull
gen:
docker run -v $(PREFIX)/external/customers:/api citradigital/toldata:v0.1.1 \
-I /api/ \
/api/customers.proto \
--toldata_out=grpc:/api --gogofaster_out=plugins=grpc:/api
docker run -v $(PREFIX)/external/orders:/api citradigital/toldata:v0.1.1 \
-I /api/ \
/api/orders.proto \
--toldata_out=grpc:/api --gogofaster_out=plugins=grpc:/api
docker run -v $(PREFIX)/external/briva:/api citradigital/toldata:v0.1.1 \
-I /api/ \
/api/briva.proto \
--toldata_out=grpc:/api --gogofaster_out=plugins=grpc:/api
docker run -v $(PREFIX)/external/halodoc:/api citradigital/toldata:v0.1.1 \
-I /protobuf -I /api/ \
/api/halodoc.proto \
--toldata_out=grpc:/api --gogofaster_out=plugins=grpc:/api
docker run -v $(PREFIX)/external/kirimsurel:/api citradigital/toldata:v0.1.1 \
-I /api/ \
/api/kirimsurel.proto \
--toldata_out=grpc:/api --gogofaster_out=plugins=grpc:/api
docker run -v $(PREFIX)/external/smsblast:/api citradigital/toldata:v0.1.1 \
-I /api/ \
/api/smsblast.proto \
--toldata_out=grpc:/api --gogofaster_out=plugins=grpc:/api
docker run -v $(PREFIX)/external/time:/api citradigital/toldata:v0.1.1 \
-I /api/ \
/api/time.proto \
--toldata_out=grpc:/api --gogofaster_out=plugins=grpc:/api
docker run -v $(PREFIX)/external/blob:/api citradigital/toldata:v0.1.1 \
-I /api/ \
/api/blob.proto \
--toldata_out=grpc:/api --gogofaster_out=plugins=grpc:/api
docker run -v $(PREFIX)/external/customerauth:/api citradigital/toldata:v0.1.1 \
-I /api/ \
/api/customerauth.proto \
--toldata_out=grpc:/api --gogofaster_out=plugins=grpc:/api
docker run -v $(PREFIX)/external/vouchers:/api citradigital/toldata:v0.1.1 \
-I /api/ \
/api/vouchers.proto \
--toldata_out=grpc:/api --gogofaster_out=plugins=grpc:/api
docker run -v $(PREFIX)/external/channels:/api citradigital/toldata:v0.1.1 \
-I /api/ \
/api/channels.proto \
--toldata_out=grpc:/api --gogofaster_out=plugins=grpc:/api
docker run -v $(PREFIX):/gen -v $(PREFIX)/api:/api citradigital/toldata:v0.1.1 \
-I /protobuf -I /api/ \
/api/simplyservice.proto \
--toldata_out=grpc:/gen --gogofaster_out=plugins=grpc:/gen
gen-simply-only:
docker run -v $(PREFIX):/gen -v $(PREFIX)/api:/api citradigital/toldata:v0.1.1 \
-I /protobuf -I /api/ \
/api/simplyservice.proto \
--toldata_out=grpc:/gen --gogofaster_out=plugins=grpc:/gen
swagger: gen-simply-only
docker run -v --rm -it -v $(PREFIX):/work -w /work quay.io/goswagger/swagger generate spec -m -o swagger.json
swagger_image: swagger
docker-compose -f ${RECIPE} -p ${NAMESPACE} build --no-cache swagger
swagger_serve: swagger_image
docker run -p 30000:8080 docker.brilife.citradigital.dev/core/simply-swagger:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment