Last active
February 5, 2016 05:02
-
-
Save ryanhatfield/7c7fac637705bcfb55ef to your computer and use it in GitHub Desktop.
Minimal web docker container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is just a proof of concept but could be used to make simple web servers | |
# put this in the root of your 'botlink-fly' repo and run 'make', then 'make deploy' | |
CURRENT_PATH := $(shell pwd) | |
DEPLOY_TMP_NAME := deploy-tmp | |
DEPLOY_TMP := $(CURRENT_PATH)/$(DEPLOY_TMP_NAME) | |
DEPLOY_APP_NAME := fly-test | |
DEPLOY_DEIS_URL := deis.platform.botlink.com | |
GO_CMD_PATH := $(shell which go) | |
GO_BUILD_COMMAND := "CGO_ENABLED=0 GOOS=linux $(GO_CMD_PATH) build -a -installsuffix cgo -o $(DEPLOY_TMP)/server $(DEPLOY_TMP)/server.go" | |
default: build | |
setup: | |
@echo "Calling 'npm install'" | |
@npm install | |
@echo "Calling 'bower install'" | |
@bower install | |
build: | |
$(MAKE) setup | |
@echo "Calling 'ember build'" | |
@ember build | |
deploy: | |
@$(MAKE) pre_deploy | |
@cd $(DEPLOY_TMP) && deis git:remote -a $(DEPLOY_APP_NAME) && git push deis master -f | |
pre_deploy: | |
@$(MAKE) deploy_clean | |
mkdir $(DEPLOY_TMP) | |
@if [ ! -d dist ]; then echo "Run 'make build' first, dist folder missing." ; exit 1 ; fi | |
$(MAKE) out_server | |
$(MAKE) out_dockerfile | |
@$(MAKE) compile_server | |
@rm $(DEPLOY_TMP)/server.go | |
@cp -r $(DEPLOY_TMP)/../dist $(DEPLOY_TMP)/dist | |
@cd $(DEPLOY_TMP) && git init && git add . && git commit -m "Add dist files" | |
compile_server: | |
/bin/bash -c $(GO_BUILD_COMMAND) | |
deploy_clean: | |
@rm -rf $(DEPLOY_TMP) | |
out_server: | |
@echo "package main" > $(DEPLOY_TMP)/server.go | |
@echo 'import "net/http"' >> $(DEPLOY_TMP)/server.go | |
@echo 'func main() {' >> $(DEPLOY_TMP)/server.go | |
@echo ' panic(http.ListenAndServe(":3000", http.FileServer(http.Dir("/www"))))' >> $(DEPLOY_TMP)/server.go | |
@echo '}' >> $(DEPLOY_TMP)/server.go | |
out_dockerfile: | |
@echo 'FROM scratch' > $(DEPLOY_TMP)/Dockerfile | |
@echo 'ADD server /' >> $(DEPLOY_TMP)/Dockerfile | |
@echo 'ADD dist /www' >> $(DEPLOY_TMP)/Dockerfile | |
@echo 'EXPOSE 3000' >> $(DEPLOY_TMP)/Dockerfile | |
@echo 'CMD ["/server"]' >> $(DEPLOY_TMP)/Dockerfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment