simplify deployment tooling
This commit is contained in:
+24
-11
@@ -8,19 +8,13 @@ generate:
|
|||||||
test:
|
test:
|
||||||
go test -json ./... | docker run -i ghcr.io/gotesttools/gotestfmt:latest
|
go test -json ./... | docker run -i ghcr.io/gotesttools/gotestfmt:latest
|
||||||
|
|
||||||
.PHONY: migrate-dev
|
|
||||||
migrate-dev:
|
|
||||||
./migrate_dev.sh
|
|
||||||
|
|
||||||
.PHONY: migrate-prod
|
|
||||||
migrate-prod:
|
|
||||||
./migrate_prod.sh
|
|
||||||
|
|
||||||
# ex: make create-migration ARG="create_users_table"
|
# ex: make create-migration ARG="create_users_table"
|
||||||
create-migration:
|
create-migration:
|
||||||
echo "Creating migration with name $(ARG)"
|
echo "Creating migration with name $(ARG)"
|
||||||
docker run -v ./migrations:/migrations --network host migrate/migrate create -ext sql -seq -dir /migrations $(ARG)
|
docker run -v ./migrations:/migrations --network host migrate/migrate create -ext sql -seq -dir /migrations $(ARG)
|
||||||
|
|
||||||
|
# ---- Database access ----
|
||||||
|
|
||||||
dev-database:
|
dev-database:
|
||||||
kubectl run postgres-client \
|
kubectl run postgres-client \
|
||||||
--rm -it --image=postgres:latest \
|
--rm -it --image=postgres:latest \
|
||||||
@@ -35,11 +29,30 @@ prod-database:
|
|||||||
--context prod \
|
--context prod \
|
||||||
--command -- /bin/bash -c "psql \$$LLINK_POSTGRES_CONNECTION_URL"
|
--command -- /bin/bash -c "psql \$$LLINK_POSTGRES_CONNECTION_URL"
|
||||||
|
|
||||||
|
# ---- Migrations ----
|
||||||
|
# NOTE: if you run into issues with 'dirty' migrations: https://github.com/golang-migrate/migrate/issues/282#issuecomment-530743258
|
||||||
|
|
||||||
|
DEV_REPO := us-west2-docker.pkg.dev/flowy-dev-440017/deployments
|
||||||
|
PROD_REPO := us-west2-docker.pkg.dev/flowy-prod-440017/deployments
|
||||||
|
|
||||||
|
.PHONY: migrate-dev
|
||||||
|
migrate-dev:
|
||||||
|
kubectl delete job migrations --ignore-not-found --context=dev
|
||||||
|
SKAFFOLD_DEFAULT_REPO=$(DEV_REPO) skaffold run -p migrations --kube-context dev
|
||||||
|
|
||||||
|
.PHONY: migrate-prod
|
||||||
|
migrate-prod:
|
||||||
|
kubectl delete job migrations --ignore-not-found --context=prod
|
||||||
|
SKAFFOLD_DEFAULT_REPO=$(PROD_REPO) skaffold run -p migrations --kube-context prod --tail
|
||||||
|
|
||||||
|
# ---- Deploy ----
|
||||||
|
# Use MODULE=orion or MODULE=worker to deploy a single service, e.g.:
|
||||||
|
# make deploy-dev MODULE=orion
|
||||||
|
|
||||||
.PHONY: deploy-dev
|
.PHONY: deploy-dev
|
||||||
deploy-dev: generate test
|
deploy-dev: generate test
|
||||||
./deploy_dev.sh
|
SKAFFOLD_DEFAULT_REPO=$(DEV_REPO) skaffold run -p dev $(if $(MODULE),-m $(MODULE)) --kube-context dev --port-forward --tail
|
||||||
|
|
||||||
.PHONY: deploy-prod
|
.PHONY: deploy-prod
|
||||||
deploy-prod: generate test
|
deploy-prod: generate test
|
||||||
./deploy_prod.sh
|
SKAFFOLD_DEFAULT_REPO=$(PROD_REPO) skaffold run -p prod $(if $(MODULE),-m $(MODULE)) --kube-context prod --port-forward --tail
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# Orion
|
||||||
|
|
||||||
|
API server and worker services for llink.
|
||||||
|
|
||||||
|
## Deploy
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Deploy all services
|
||||||
|
make deploy-dev
|
||||||
|
make deploy-prod
|
||||||
|
|
||||||
|
# Deploy a single service
|
||||||
|
make deploy-dev MODULE=orion
|
||||||
|
make deploy-dev MODULE=worker
|
||||||
|
```
|
||||||
|
|
||||||
|
## Migrations
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make migrate-dev
|
||||||
|
make migrate-prod
|
||||||
|
|
||||||
|
# Create a new migration
|
||||||
|
make create-migration ARG="create_users_table"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Database Access
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make dev-database
|
||||||
|
make prod-database
|
||||||
|
```
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
export KUBE_CONTEXT=dev
|
|
||||||
export SKAFFOLD_DEFAULT_REPO=us-west2-docker.pkg.dev/flowy-dev-440017/deployments
|
|
||||||
skaffold run -p dev --kube-context $KUBE_CONTEXT --port-forward --tail
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
export KUBE_CONTEXT=prod
|
|
||||||
export SKAFFOLD_DEFAULT_REPO=us-west2-docker.pkg.dev/flowy-prod-440017/deployments
|
|
||||||
skaffold run -p prod --kube-context $KUBE_CONTEXT --port-forward --tail
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
echo "# NOTE: if you run into issues with 'dirty' migrations: https://github.com/golang-migrate/migrate/issues/282#issuecomment-530743258"
|
|
||||||
|
|
||||||
export KUBE_CONTEXT=dev
|
|
||||||
export SKAFFOLD_DEFAULT_REPO=us-west2-docker.pkg.dev/flowy-dev-440017/deployments
|
|
||||||
kubectl delete job migrations --ignore-not-found --context=$KUBE_CONTEXT
|
|
||||||
skaffold run -p migrations --kube-context $KUBE_CONTEXT
|
|
||||||
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
echo "# NOTE: if you run into issues with 'dirty' migrations: https://github.com/golang-migrate/migrate/issues/282#issuecomment-530743258"
|
|
||||||
|
|
||||||
export KUBE_CONTEXT=prod
|
|
||||||
export SKAFFOLD_DEFAULT_REPO=us-west2-docker.pkg.dev/flowy-prod-440017/deployments
|
|
||||||
kubectl delete job migrations --ignore-not-found --context=$KUBE_CONTEXT
|
|
||||||
skaffold run -p migrations --kube-context $KUBE_CONTEXT --tail
|
|
||||||
|
|
||||||
+45
-19
@@ -1,14 +1,12 @@
|
|||||||
apiVersion: skaffold/v4beta11
|
apiVersion: skaffold/v4beta11
|
||||||
kind: Config
|
kind: Config
|
||||||
metadata:
|
metadata:
|
||||||
name: llink-services
|
name: migrations
|
||||||
build:
|
build:
|
||||||
local: {}
|
local: {}
|
||||||
tagPolicy:
|
tagPolicy:
|
||||||
gitCommit:
|
gitCommit:
|
||||||
variant: AbbrevCommitSha
|
variant: AbbrevCommitSha
|
||||||
|
|
||||||
# NOTE: we use different profiles for a simpler mental model
|
|
||||||
profiles:
|
profiles:
|
||||||
- name: migrations
|
- name: migrations
|
||||||
build:
|
build:
|
||||||
@@ -22,45 +20,73 @@ profiles:
|
|||||||
- k8s/migrations.yaml
|
- k8s/migrations.yaml
|
||||||
deploy:
|
deploy:
|
||||||
kubectl: {}
|
kubectl: {}
|
||||||
|
---
|
||||||
|
apiVersion: skaffold/v4beta11
|
||||||
|
kind: Config
|
||||||
|
metadata:
|
||||||
|
name: orion
|
||||||
|
build:
|
||||||
|
local: {}
|
||||||
|
tagPolicy:
|
||||||
|
gitCommit:
|
||||||
|
variant: AbbrevCommitSha
|
||||||
|
profiles:
|
||||||
- name: dev
|
- name: dev
|
||||||
build:
|
build:
|
||||||
hooks:
|
|
||||||
before:
|
|
||||||
# already run in make test
|
|
||||||
# - command: ["go", "test", "./..."]
|
|
||||||
artifacts:
|
artifacts:
|
||||||
- image: orion
|
- image: orion
|
||||||
context: .
|
context: .
|
||||||
docker:
|
docker:
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
- image: particleprocessorworker
|
|
||||||
context: .
|
|
||||||
docker:
|
|
||||||
dockerfile: Dockerfile.particleprocessorworker
|
|
||||||
manifests:
|
manifests:
|
||||||
rawYaml:
|
rawYaml:
|
||||||
- k8s/dev/*
|
- k8s/dev/orion.yaml
|
||||||
deploy:
|
deploy:
|
||||||
kubectl: {}
|
kubectl: {}
|
||||||
|
|
||||||
- name: prod
|
- name: prod
|
||||||
build:
|
build:
|
||||||
hooks:
|
|
||||||
before:
|
|
||||||
# already run in make test
|
|
||||||
# - command: ["go", "test", "./..."]
|
|
||||||
artifacts:
|
artifacts:
|
||||||
- image: orion
|
- image: orion
|
||||||
context: .
|
context: .
|
||||||
docker:
|
docker:
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
manifests:
|
||||||
|
rawYaml:
|
||||||
|
- k8s/prod/orion.yaml
|
||||||
|
deploy:
|
||||||
|
kubectl: {}
|
||||||
|
---
|
||||||
|
apiVersion: skaffold/v4beta11
|
||||||
|
kind: Config
|
||||||
|
metadata:
|
||||||
|
name: worker
|
||||||
|
build:
|
||||||
|
local: {}
|
||||||
|
tagPolicy:
|
||||||
|
gitCommit:
|
||||||
|
variant: AbbrevCommitSha
|
||||||
|
profiles:
|
||||||
|
- name: dev
|
||||||
|
build:
|
||||||
|
artifacts:
|
||||||
- image: particleprocessorworker
|
- image: particleprocessorworker
|
||||||
context: .
|
context: .
|
||||||
docker:
|
docker:
|
||||||
dockerfile: Dockerfile.particleprocessorworker
|
dockerfile: Dockerfile.particleprocessorworker
|
||||||
manifests:
|
manifests:
|
||||||
rawYaml:
|
rawYaml:
|
||||||
- k8s/prod/*
|
- k8s/dev/particleprocessorworker.yaml
|
||||||
|
deploy:
|
||||||
|
kubectl: {}
|
||||||
|
- name: prod
|
||||||
|
build:
|
||||||
|
artifacts:
|
||||||
|
- image: particleprocessorworker
|
||||||
|
context: .
|
||||||
|
docker:
|
||||||
|
dockerfile: Dockerfile.particleprocessorworker
|
||||||
|
manifests:
|
||||||
|
rawYaml:
|
||||||
|
- k8s/prod/particleprocessorworker.yaml
|
||||||
deploy:
|
deploy:
|
||||||
kubectl: {}
|
kubectl: {}
|
||||||
|
|||||||
Reference in New Issue
Block a user