Skip to content
This repository was archived by the owner on Oct 31, 2021. It is now read-only.

Commit da43637

Browse files
committed
Significantly improved docker builds, and local work.
Building containers for running stuff locally in minikube no longer requires docker for desktop. Instead the docker builds will use the minikube docker env (minkube's own docker socket) for builds, which makes this simpler overall and reduces dependencies on the developer. Added a docker ignore which ignores everything except for the go.mod and go.sum file and anything in the pkg directory. Everything else is excluded; making the build context very small.
1 parent baf0887 commit da43637

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

.dockerignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ignore everything
2+
**
3+
4+
# Allow the golang stuff.
5+
!/pkg/**
6+
!/go.mod
7+
!/go.sum
8+

Makefile.docker

+6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ DOCKER_IMAGE = rest-api
44
default-docker:
55
$(error Please run a specific target)
66

7+
ifdef CI
78
wait-for-docker:
89
@for i in 1 2 3 4 5; do (docker info > /dev/null 2>&1) && break || echo "Waiting for docker to start..." && sleep 15; done
10+
else
11+
wait-for-docker:
12+
@eval $$(minikube docker-env) && for i in 1 2 3 4 5; do (docker info > /dev/null 2>&1) && break || echo "Waiting for docker to start..." && sleep 15; done
13+
endif
14+
915

1016
VERSION_TAG = $(shell git rev-parse HEAD)
1117
BASE_IMAGE = $(DOCKER_REPOSITORY)/$(DOCKER_IMAGE)

Makefile.local

+12-9
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ setup-certificates: $(LOCAL_DIR)
105105
openssl req -new -x509 -addext "subjectAltName = DNS:*.$(LOCAL_DOMAIN)" -key $(KEY_PATH) -out $(CERT_PATH) -days 3650 \
106106
-subj /CN=*.$(LOCAL_DOMAIN) || make help-certificates-openssl
107107
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain $(CERT_PATH)
108-
(killall Docker && open /Applications/Docker.app) || true
109108
mkdir -p $(HOME)/.minikube/certs
110109
openssl x509 -in $(CERT_PATH) -out $(HOME)/.minikube/certs/$(LOCAL_DOMAIN).pem
111110

@@ -182,15 +181,15 @@ GO_HASH=$(shell find -s $(PWD)/pkg -type f -exec shasum {} \; | shasum | cut -d
182181
BASE_IMAGE_NAME = registry.$(LOCAL_DOMAIN)/$(REST_API_IMAGE_NAME)
183182
IMAGE_NAME = $(BASE_IMAGE_NAME):$(GO_HASH)
184183
build-rest-api-mini: wait-for-docker
185-
docker build \
184+
eval $$(minikube docker-env) && docker build \
186185
--cache-from=$(BASE_IMAGE_NAME):latest \
187186
--build-arg REVISION=$(RELEASE_REVISION) \
188187
--build-arg BUILD_TIME=$(BUILD_TIME) \
189188
-t $(IMAGE_NAME) \
190189
-t $(BASE_IMAGE_NAME):latest \
191-
-f Dockerfile .
192-
docker push $(IMAGE_NAME)
193-
docker push $(BASE_IMAGE_NAME):latest
190+
-f Dockerfile . && \
191+
docker push $(IMAGE_NAME) && \
192+
docker push $(BASE_IMAGE_NAME):latest
194193
yq e '.image.tag = "$(GO_HASH)"' -i $(VALUES)
195194

196195
deploy-redis:
@@ -258,7 +257,11 @@ local-api:
258257
LOCAL_IP=$(LOCAL_IP) $(YQ) e '.subsets[0].addresses[0].ip = strenv(LOCAL_IP)' $(PWD)/minikube/api-endpoint.yaml | $(KUBECTL) apply -f -
259258
$(KUBECTL) get svc/$(REST_API_IMAGE_NAME) -n $(MINIKUBE_NAMESPACE) -o yaml | $(YQ) e 'del(.spec.selector)' - | $(KUBECTL) apply -f -
260259
$(KUBECTL) scale deploy/$(REST_API_IMAGE_NAME) --replicas=0 -n $(MINIKUBE_NAMESPACE)
261-
unset TMUX && tmux new-session 'minikube tunnel --cleanup'
260+
ifdef TMUX # If the user is already in tmux then just spawn a new session and switch to it.
261+
tmux new -s local-api -d 'minikube tunnel --cleanup' && tmux switch -t local-api || true
262+
else # If the user is not, start a new session and then enter tmux to attach.
263+
tmux new -s local-api -d 'minikube tunnel --cleanup' && tmux attach -t local-api || true
264+
endif
262265
$(KUBECTL) delete svc/$(REST_API_IMAGE_NAME) --namespace $(MINIKUBE_NAMESPACE)
263266
$(KUBECTL) apply -f $(LOCAL_REST_API_DEPLOY) --namespace $(MINIKUBE_NAMESPACE)
264267
$(KUBECTL) scale deploy/$(REST_API_IMAGE_NAME) --replicas=1 -n $(MINIKUBE_NAMESPACE)
@@ -337,11 +340,11 @@ unseal-vault-mini: $(VAULT_JSON)
337340
###################### gocraft/work UI ##################################
338341
WORK_IMAGE_NAME=registry.$(LOCAL_DOMAIN)/work
339342
work-mini:
340-
docker build \
343+
eval $$(minikube docker-env) && docker build \
341344
--cache-from=$(WORK_IMAGE_NAME):latest \
342345
-t $(WORK_IMAGE_NAME):latest \
343-
-f Dockerfile.work .
344-
docker push $(WORK_IMAGE_NAME):latest
346+
-f Dockerfile.work . && \
347+
docker push $(WORK_IMAGE_NAME):latest
345348
$(KUBECTL) apply -f $(PWD)/minikube/work.yaml \
346349
--namespace $(MINIKUBE_NAMESPACE)
347350
$(KUBECTL) rollout status deploy/work \

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This will allow you to access the REST API via `https://api.monetr.mini`.
3030
**NOTE:** This is still being tuned and is subject to change significantly. This also requires the following
3131
to be installed on your computer.
3232
- minikube
33-
- docker
33+
- docker (Docker for Desktop not required)
3434
- hyperkit
3535
- kubectl
3636
- openssl (not the LibreSSL version)

0 commit comments

Comments
 (0)