Skip to content

Commit

Permalink
[guestbook-go] Use multi-stage build (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
serathius authored and ahmetb committed Mar 20, 2018
1 parent e4cc298 commit 188c3d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
20 changes: 13 additions & 7 deletions guestbook-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM busybox:ubuntu-14.04

ADD ./guestbook_bin /app/guestbook
ADD ./public/index.html /app/public/index.html
ADD ./public/script.js /app/public/script.js
ADD ./public/style.css /app/public/style.css
FROM golang:1.10.0
RUN go get github.com/codegangsta/negroni \
github.com/gorilla/mux \
github.com/xyproto/simpleredis
WORKDIR /app
ADD ./main.go .
RUN CGO_ENABLED=0 GOOS=linux go build -o main .

FROM scratch
WORKDIR /app
CMD ["./guestbook"]
COPY --from=0 /app/main .
COPY ./public/index.html public/index.html
COPY ./public/script.js public/script.js
COPY ./public/style.css public/style.css
CMD ["/app/main"]
EXPOSE 3000
9 changes: 2 additions & 7 deletions guestbook-go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@ release: clean build push clean

# builds a docker image that builds the app and packages it into a minimal docker image
build:
@cp ../../bazel-bin/examples/guestbook-go/guestbook-go guestbook_bin
docker build --pull --rm --force-rm -t ${REGISTRY}/guestbook-builder .
docker run --rm ${REGISTRY}/guestbook-builder | docker build --pull -t "${REGISTRY}/guestbook:${VERSION}" -
docker build -t ${REGISTRY}/guestbook:${VERSION} .

# push the image to an registry
push:
gcloud docker -- push ${REGISTRY}/guestbook:${VERSION}

# remove previous images and containers
clean:
rm -f guestbook_bin
docker rm -f ${REGISTRY}/guestbook-builder 2> /dev/null || true
docker rmi -f ${REGISTRY}/guestbook-builder || true
docker rmi -f "${REGISTRY}/guestbook:${VERSION}" || true
docker rm -f ${REGISTRY}/guestbook:${VERSION} 2> /dev/null || true

.PHONY: release clean build push

0 comments on commit 188c3d9

Please sign in to comment.