Last active
November 12, 2018 15:36
-
-
Save mrgleeco/cc75347baaf9471b477ba9830bbefc06 to your computer and use it in GitHub Desktop.
generic python 2.7 app 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
| ## NOTE: multi-stage builds require docker ce > 17 | |
| ## NOTE: grep for myapp or my-app here as placeholders | |
| FROM python:2.7-slim-stretch as app-base | |
| # here install some basics you might want need | |
| RUN apt-get update && \ | |
| apt-get upgrade --yes && \ | |
| apt-get install --yes \ | |
| git \ | |
| curl \ | |
| vim-tiny && \ | |
| apt-get --purge remove --yes \ | |
| manpages \ | |
| manpages-dev && \ | |
| apt-get autoremove --yes && \ | |
| apt-get autoclean && \ | |
| rm -rf /var/lib/apt/lists/* | |
| ## next layer is all the python | |
| FROM app-base as app-python | |
| RUN mkdir -p /src /opt/python | |
| WORKDIR /src | |
| COPY . /src | |
| RUN pip install --prefix=/opt/python -r /src/requirements.txt | |
| RUN pip --no-cache-dir install --prefix=/opt/python . | |
| ## Final layer has any final bits like adduser or system tweaks | |
| FROM app-base as ap | |
| MAINTAINER USER <[email protected]> | |
| ARG RELEASE_VERSION | |
| ARG BUILD_DATE | |
| ARG VCS_REF | |
| LABEL \ | |
| org.label-schema.build-date=$BUILD_DATE \ | |
| org.label-schema.vcs-ref=$VCS_REF \ | |
| org.label-schema.vcs-url="https://github.com/my-org/my-repo" | |
| ENV REFRESHED_AT=${BUILD_DATE} \ | |
| RELEASE_VERSION=${RELEASE_VERSION} \ | |
| VCS_REF=${VCS_REF} | |
| COPY docker-entrypoint.sh / | |
| # copy as late as possible | |
| COPY --from=app-python /opt/python /usr/local | |
| ENTRYPOINT ["/docker-entrypoint.sh"] | |
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
| # NOTE: grep for myapp or my-app here as placeholders | |
| SHELL=/bin/bash | |
| DOCKER_IMG := us.gcr.io/my-project/my-app | |
| TDATE := $(shell date -u +"%Y-%m-%dT%H:%M:%S%z") | |
| VCS_REF := $(shell git rev-parse --short HEAD) | |
| APPLIB_VERSION := $(shell python -c 'import myapp.__version__ as v; print v.__version__') | |
| RELEASE_VERSION := $(APPLIB_VERSION)-$(VCS_REF) | |
| .PHONY: build # full container build | |
| build: | |
| docker build \ | |
| --build-arg VCS_REF=$(VCS_REF) \ | |
| --build-arg BUILD_DATE=$(TDATE) \ | |
| --build-arg RELEASE_VERSION=$(RELEASE_VERSION) \ | |
| . -t $(DOCKER_IMG):$(RELEASE_VERSION) | |
| .PHONY: push # Push official release container | |
| push: | |
| docker push $(DOCKER_IMG):$(RELEASE_VERSION) | |
| .PHONY: push-latest # Push official release container | |
| push-latest: push | |
| docker tag $(DOCKER_IMG):$(RELEASE_VERSION) $(DOCKER_IMG):latest | |
| docker push $(DOCKER_IMG):latest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment