Skip to content

Commit 5d47819

Browse files
committed
add docker build recipies
1 parent bbaba40 commit 5d47819

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
web/node_modules
2+
tools/
3+
target/

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ DEBUG ?= true
88
all: build
99

1010
include build.mk
11+
include docker.mk
1112

1213
.PHONY:run
1314
run:

build/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM node:13-alpine as ui-build
2+
COPY web .
3+
RUN yarn install --silent && yarn build
4+
5+
FROM golang:1.13-alpine as build
6+
COPY cmd ./cmd
7+
COPY pkg ./pkg
8+
COPY go.mod .
9+
COPY go.sum .
10+
RUN go build -o server ./cmd/playground
11+
12+
FROM golang:1.13-alpine as production
13+
WORKDIR /opt/playground
14+
COPY data ./data
15+
COPY --from=ui-build web/build ./public
16+
COPY --from=build server .
17+
EXPOSE 8000
18+
CMD ['/opt/playground/server', '-f=/opt/playground/data/packages.json']

docker.mk

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
DOCKERFILE ?= ./build/Dockerfile
2+
IMG_NAME ?= x1unix/go-playground
3+
TAG ?= 1.0.0
4+
5+
.PHONY: docker
6+
docker: docker-login docker-make-image
7+
@echo "- Pushing $(IMG_NAME):$(TAG) (as latest)...'
8+
docker push $(IMG_NAME):$(TAG)
9+
docker push $(IMG_NAME):latest
10+
11+
.PHONY: docker-login
12+
docker-login:
13+
@if [ -z "$(DOCKER_USER)" ]; then\
14+
echo "required parameter DOCKER_USER is undefined" && exit 1; \
15+
fi;
16+
@if [ -z "$(DOCKER_PASS)" ]; then\
17+
echo "required parameter DOCKER_PASS is undefined" && exit 1; \
18+
fi;
19+
@docker login -u $(DOCKER_USER) -p $(DOCKER_PASS) && echo "- Docker login success";
20+
21+
.PHONY: docker-make-image
22+
docker-make-image:
23+
@echo "- Building '$(IMG_NAME):latest' $(TAG)..."
24+
docker image build -t $(IMG_NAME):latest -t $(IMG_NAME):$(TAG) -f $(DOCKERFILE) .

0 commit comments

Comments
 (0)