diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000000..c28a7f516db1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.git +.config +output/ +Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000000..93b77e6c11cb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,59 @@ +## Build base image +FROM debian:buster AS base + +RUN apt-get update && apt-get install -y \ + build-essential \ + g++-multilib \ + cmake \ + git \ + file \ + bc \ + rsync \ + bison \ + flex \ + gettext \ + texinfo \ + wget \ + cpio \ + python \ + unzip \ + mercurial \ + subversion \ + libncurses5-dev \ + libc6-dev-i386 \ + bzr \ + squashfs-tools \ + u-boot-tools \ + vim \ + && rm -rf /var/lib/apt/lists/* + +RUN useradd --user-group --system --create-home --no-log-init buildroot + +## Build buildroot +FROM base AS builder +ARG CONFIG + +RUN mkdir /opt/buildroot && chown buildroot /opt/buildroot +WORKDIR /opt/buildroot + +USER buildroot + +COPY --chown=buildroot:buildroot . /opt/buildroot + +RUN make od_${CONFIG}_defconfig BR2_EXTERNAL=board/opendingux +RUN make source +RUN CONFIG=${CONFIG} ./rebuild.sh +RUN tar xf output/${CONFIG}/images/opendingux-${CONFIG}-toolchain.*.tar.xz + +## Copy assets to the final image +FROM base +ARG CONFIG + +COPY --from=builder /opt/buildroot/${CONFIG}-toolchain /opt/${CONFIG}-toolchain + +WORKDIR /opt/${CONFIG}-toolchain +ENV PATH ${PATH}:/opt/${CONFIG}-toolchain/bin + +RUN ./relocate-sdk.sh + +USER buildroot diff --git a/Makefile b/Makefile index 9d6b96247754..4e893ed0a217 100644 --- a/Makefile +++ b/Makefile @@ -1235,3 +1235,6 @@ include docs/manual/manual.mk .PHONY: $(noconfig_targets) endif #umask / $(CURDIR) / $(O) + +# Include docker-related stuff +include support/misc/docker.mk diff --git a/support/misc/docker.mk b/support/misc/docker.mk new file mode 100644 index 000000000000..cb9b3a6fd94c --- /dev/null +++ b/support/misc/docker.mk @@ -0,0 +1,36 @@ +DOCKER_TAG_REVISION := $(or $(DOCKER_TAG_REVISION),$(shell git rev-parse HEAD 2> /dev/null || true)) +DOCKER_TAG_DATE := $(or \ + $(DOCKER_TAG_DATE), \ + $(shell (git log -1 --format="%at" 2> /dev/null || true) | xargs -I{} date -d @{} +%Y%m%d)) + +CONFIGS=gcw0 rs90 +CONFIG_IMAGES=$(addsuffix -docker-image, $(CONFIGS)) + +.PHONY: publish-docker-images $(CONFIG_IMAGES) $(addprefix push-, $(CONFIG_IMAGES)) $(addprefix publish-, $(CONFIG_IMAGES)) docker-image push-docker-image + +publish-docker-images: $(addprefix publish-, $(CONFIG_IMAGES)) + +$(CONFIG_IMAGES): %-docker-image: + make docker-image DOCKER_CONFIG=$* + +$(addprefix push-, $(CONFIG_IMAGES)): push-%-docker-image: + make push-docker-image DOCKER_CONFIG=$* + +$(addprefix publish-, $(CONFIG_IMAGES)): publish-%-docker-image: + $(MAKE) $*-docker-image push-$*-docker-image + +docker-image: + test -n "$(DOCKER_CONFIG)" # $$DOCKER_CONFIG + test -n "$(DOCKER_IMAGE)" # $$DOCKER_IMAGE + docker build \ + -t ${DOCKER_IMAGE}:${DOCKER_CONFIG}-${DOCKER_TAG_REVISION} \ + -t ${DOCKER_IMAGE}:${DOCKER_CONFIG}-${DOCKER_TAG_DATE} \ + -t ${DOCKER_IMAGE}:${DOCKER_CONFIG}-latest \ + --build-arg CONFIG=${DOCKER_CONFIG} . + +push-docker-image: + test -n "$(DOCKER_CONFIG)" # $$DOCKER_CONFIG + test -n "$(DOCKER_IMAGE)" # $$DOCKER_IMAGE + docker push ${DOCKER_IMAGE}:${DOCKER_CONFIG}-${DOCKER_TAG_REVISION} + docker push ${DOCKER_IMAGE}:${DOCKER_CONFIG}-${DOCKER_TAG_DATE} + docker push ${DOCKER_IMAGE}:${DOCKER_CONFIG}-latest