From ef3563dd0bc9d7d107d6689921b515516c130331 Mon Sep 17 00:00:00 2001 From: alswl Date: Sat, 10 Dec 2022 19:51:56 +0800 Subject: [PATCH] feat: makefile and docker compose --- Makefile | 89 +++++++++++++++++++++++++++++++++++++++ VERSION | 1 + docker-compose.yaml | 22 ++++++++++ excalidraw.env.production | 21 +++++++++ 4 files changed, 133 insertions(+) create mode 100644 Makefile create mode 100644 VERSION create mode 100644 docker-compose.yaml create mode 100644 excalidraw.env.production diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..20c2725 --- /dev/null +++ b/Makefile @@ -0,0 +1,89 @@ +# The old school Makefile, following are required targets. The Makefile is written +# to allow building multiple binaries. You are free to add more targets or change +# existing implementations, as long as the semantics are preserved. +# +# make - default to 'build' target +# make test - run unit test +# make build - build local binary targets +# make container - build containers +# make push - push containers +# make clean - clean up targets +# +# The makefile is also responsible to populate project version information. + +# +# Tweak the variables based on your project. +# +SHELL := /bin/bash +NOW_SHORT := $(shell date +%Y%m%d%H%M) + +PROJECT := excalidraw-collaboration +# Target binaries. You can build multiple binaries for a single project. +TARGETS := excalidraw excalidraw-room excalidraw-storage-backend + +# Container registries. +REGISTRIES ?= "" + +# Container image prefix and suffix added to targets. +# The final built images are: +# $[REGISTRY]$[IMAGE_PREFIX]$[TARGET]$[IMAGE_SUFFIX]:$[VERSION] +# $[REGISTRY] is an item from $[REGISTRIES], $[TARGET] is an item from $[TARGETS]. +IMAGE_PREFIX ?= $(strip ) +IMAGE_SUFFIX ?= $(strip ) + +# This repo's root import path (under GOPATH). +ROOT := github.com/alswl/excalidraw.alswl.com + +# Git commit sha. +COMMIT := $(strip $(shell git rev-parse --short HEAD 2>/dev/null)) +COMMIT := $(COMMIT)$(shell git diff-files --quiet || echo '-dirty') +COMMIT := $(if $(COMMIT),$(COMMIT),"Unknown") + +# Current version of the project. +MAJOR_VERSION = 0 +MINOR_VERSION = 1 +PATCH_VERSION = 0 +BUILD_VERSION = $(COMMIT) +VERSION ?= v$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)-$(BUILD_VERSION) + +.PHONY: help +help: ## Display this help + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + +.PHONY: patch +patch: ## Patch endpoints + @echo "# you can edit excalidraw.env.production to change endpoints" + cp excalidraw.env.production excalidraw/.env.production + +.PHONY: images +images: ## Build docker images + @for target in $(TARGETS); do \ + for registry in $(REGISTRIES); do \ + image=$${registry}$(IMAGE_PREFIX)$${target}$(IMAGE_SUFFIX):$(VERSION); \ + docker build \ + -t $${image} \ + --build-arg COMMIT=$(COMMIT) \ + --progress=plain \ + -f ./$${target}/Dockerfile $${target}; \ + done; \ + done + +.PHONY: push-images +push-images: ## Push docker images + @for target in $(TARGETS); do \ + for registry in $(REGISTRIES); do \ + image=$${registry}$(IMAGE_PREFIX)$${target}$(IMAGE_SUFFIX):$(VERSION); \ + docker push $$image; \ + done; \ + done + +.PHONY: bump-version +currentVersion=$(shell head -n 1 ./VERSION) +bump-version: ## Bump images version for docker-compose + @for targe in $(TARGETS); do \ + for registry in $(REGISTRIES); do \ + image=$${registry}$(IMAGE_PREFIX)$${target}$(IMAGE_SUFFIX):$(VERSION); \ + gsed -i "s#$(image):$(currentVersion)#$(image):$(VERSION)#g" docker-compose.yaml; \ + done; \ + done + @echo "PLEASE using 'git commit -a' to commit image version changes" diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..258d34f --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +v0.1.0-3b75ea1-dirty \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..17cd42b --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,22 @@ +# sample comes from https://github.com/docker/awesome-compose + +services: + frontend: + image: excalidraw:v0.1.0-d972cac-dirty + environment: # docs https://github.com/alswl/excalidraw-storage-backend#environement-variables + - PORT=8080 + ports: + - 80:80 + + storage: + image: excalidraw-storage-backend:v0.1.0-d972cac-dirty + restart: always + environment: # docs https://github.com/alswl/excalidraw-storage-backend#environement-variables + - PORT=8081 + ports: + - 8081:8081 + + room: + image: excalidraw-room:v0.1.0-d972cac-dirty + ports: + - 8082:8080 \ No newline at end of file diff --git a/excalidraw.env.production b/excalidraw.env.production new file mode 100644 index 0000000..a13ca1f --- /dev/null +++ b/excalidraw.env.production @@ -0,0 +1,21 @@ +REACT_APP_BACKEND_V2_GET_URL=https://test.com/api/v2/ +REACT_APP_BACKEND_V2_POST_URL=https://test.com/api/v2/post/ + +REACT_APP_LIBRARY_URL=https://libraries.excalidraw.com +REACT_APP_LIBRARY_BACKEND=https://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries + +REACT_APP_HTTP_STORAGE_BACKEND_URL=http://127.0.0.1:8081/api/v2 +REACT_APP_STORAGE_BACKEND=http + +REACT_APP_PORTAL_URL= +# Fill to set socket server URL used for collaboration. +# Meant for forks only: excalidraw.com uses custom REACT_APP_PORTAL_URL flow +REACT_APP_WS_SERVER_URL=http://127.0.0.1:8082 + +REACT_APP_FIREBASE_CONFIG='{}' + +# production-only vars +REACT_APP_GOOGLE_ANALYTICS_ID=foo + +REACT_APP_PLUS_APP=https://app.excalidraw.com +