[guestbook-go] Use multi-stage build (#211)
This commit is contained in:
		
							parent
							
								
									e4cc298ab6
								
							
						
					
					
						commit
						188c3d9b92
					
				|  | @ -12,13 +12,19 @@ | ||||||
| # See the License for the specific language governing permissions and | # See the License for the specific language governing permissions and | ||||||
| # limitations under the License. | # limitations under the License. | ||||||
| 
 | 
 | ||||||
| FROM busybox:ubuntu-14.04 | FROM golang:1.10.0 | ||||||
| 
 | RUN go get github.com/codegangsta/negroni \ | ||||||
| ADD ./guestbook_bin /app/guestbook |            github.com/gorilla/mux \ | ||||||
| ADD ./public/index.html /app/public/index.html |            github.com/xyproto/simpleredis | ||||||
| ADD ./public/script.js /app/public/script.js |  | ||||||
| ADD ./public/style.css /app/public/style.css |  | ||||||
| 
 |  | ||||||
| WORKDIR /app | WORKDIR /app | ||||||
| CMD ["./guestbook"] | ADD ./main.go . | ||||||
|  | RUN CGO_ENABLED=0 GOOS=linux go build -o main . | ||||||
|  | 
 | ||||||
|  | FROM scratch | ||||||
|  | WORKDIR /app | ||||||
|  | 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 | EXPOSE 3000 | ||||||
|  |  | ||||||
|  | @ -23,9 +23,7 @@ release: clean build push clean | ||||||
| 
 | 
 | ||||||
| # builds a docker image that builds the app and packages it into a minimal docker image
 | # builds a docker image that builds the app and packages it into a minimal docker image
 | ||||||
| build: | build: | ||||||
| 	@cp ../../bazel-bin/examples/guestbook-go/guestbook-go guestbook_bin | 	docker build -t ${REGISTRY}/guestbook:${VERSION} . | ||||||
| 	docker build --pull --rm --force-rm -t ${REGISTRY}/guestbook-builder . |  | ||||||
| 	docker run --rm ${REGISTRY}/guestbook-builder | docker build --pull -t "${REGISTRY}/guestbook:${VERSION}" - |  | ||||||
| 
 | 
 | ||||||
| # push the image to an registry
 | # push the image to an registry
 | ||||||
| push: | push: | ||||||
|  | @ -33,9 +31,6 @@ push: | ||||||
| 
 | 
 | ||||||
| # remove previous images and containers
 | # remove previous images and containers
 | ||||||
| clean: | clean: | ||||||
| 	rm -f guestbook_bin | 	docker rm -f ${REGISTRY}/guestbook:${VERSION} 2> /dev/null || true | ||||||
| 	docker rm -f ${REGISTRY}/guestbook-builder 2> /dev/null || true |  | ||||||
| 	docker rmi -f ${REGISTRY}/guestbook-builder || true |  | ||||||
| 	docker rmi -f "${REGISTRY}/guestbook:${VERSION}" || true |  | ||||||
| 
 | 
 | ||||||
| .PHONY: release clean build push | .PHONY: release clean build push | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue