From 3db67431e1e4d3edc3952c5a695b0f3097e5465c Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Thu, 6 Jan 2022 21:52:39 -0500 Subject: [PATCH] single docker file build --- Dockerfile | 65 ++++++++++--------- Makefile | 24 ++----- config.yaml | 3 +- ...r-compose.yaml => docker-compose.test.yaml | 1 - 4 files changed, 40 insertions(+), 53 deletions(-) rename docker-compose.yaml => docker-compose.test.yaml (60%) diff --git a/Dockerfile b/Dockerfile index d2ca70b..1648967 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,51 +1,54 @@ +# <--- Build Args --> ARG BUILD_FROM ARG BUILD_VERSION -# ================ -# Python Build Stage -# ================ -FROM python:3.9 as pybuilder -WORKDIR /python - -COPY api/setup.py /python/setup.py -RUN python -m venv /python/venv -RUN /python/venv/bin/pip install --use-feature=in-tree-build /python/ - -# ================ -# Web Build Stage -# ================ -FROM node:16.13.0-alpine as webbuilder - -WORKDIR /web -COPY webapp/ /web -RUN npm install -RUN yarn build - -# ================ -# Main Image -# ================ +# <--- Image Setup --> FROM $BUILD_FROM - -ENV LANG C.UTF-8 - WORKDIR /data -RUN apk add gcompat python3 -RUN ln -s $(which python3) /usr/local/bin/python -COPY --from=pybuilder /python/venv /data/venv -COPY --from=webbuilder /web/build /data/web +# <--- System Wide Dependencies --> +ENV LANG C.UTF-8 +RUN echo "https://dl-3.alpinelinux.org/alpine/v3.10/main" >> /etc/apk/repositories +RUN echo "https://dl-3.alpinelinux.org/alpine/v3.10/community" >> /etc/apk/repositories +RUN apk add --no-cache \ + cargo \ + gcompat \ + nodejs \ + python3 \ + python3-dev \ + py3-pip \ + patchelf \ + rust +RUN patchelf --add-needed libgcompat.so.0 /usr/bin/python3.9 +RUN echo 'manylinux1_compatible = True' > /usr/lib/python3.9/_manylinux.py +RUN pip install -U wheel pip +# <--- Python Dependencies --> +COPY api/setup.py /data/setup.py +RUN pip install . /data + +# <--- Webapp Build --> +COPY webapp/ /data/web-builder +RUN cd /data/web-builder && npm install +RUN cd /data/web-builder && \ + yarn build && \ + cp -r /data/web-builder/build /data/web && \ + rm -rf /data/web-builder + +# <--- Api Code --> COPY api/src /data/src COPY run.sh run.sh +# <--- Environment Variables --> ENV HASSIO_TOKEN "" ENV BUILD_VERSION $BUILD_VERSION +# <--- Ports --> EXPOSE 8000 +# <--- Final --> LABEL \ io.hass.type="addon" \ io.hass.arch="armhf|aarch64|i386|amd64" - CMD [ "/data/run.sh" ] diff --git a/Makefile b/Makefile index 35e4cf0..3a0975e 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,6 @@ +DC=docker-compose -f docker-compose.build.yaml -f docker-compose.test.yaml + run_locally: - $(MAKE) build_images - docker-compose up -d - docker-compose ps - -build_images: - ARCH=amd64 docker-compose -f docker-compose.build.yaml build - ARCH=armhf docker-compose -f docker-compose.build.yaml build - ARCH=armv7 docker-compose -f docker-compose.build.yaml build - ARCH=aarch64 docker-compose -f docker-compose.build.yaml build - ARCH=i386 docker-compose -f docker-compose.build.yaml build - -push_images: - ARCH=amd64 docker-compose -f docker-compose.build.yaml push - ARCH=armhf docker-compose -f docker-compose.build.yaml - - ARCH=armv7 docker-compose -f docker-compose.build.yaml build - ARCH=aarch64 docker-compose -f docker-compose.build.yaml build - ARCH=i386 docker-compose -f docker-compose.build.yaml build - + $(DC) build + $(DC) up -d + $(DC) ps diff --git a/config.yaml b/config.yaml index 15faf3f..a55667b 100644 --- a/config.yaml +++ b/config.yaml @@ -1,9 +1,8 @@ name: Shortumation -version: 0.0.5 +version: 0.0.6 slug: shortumation url: "https://github.com/asosnovsky/Shortumation" description: "A homeassitant addon which provides better UI for automations & scripts." -image: "asosnovsky/shortumation:{arch}-latest" arch: - armhf - armv7 diff --git a/docker-compose.yaml b/docker-compose.test.yaml similarity index 60% rename from docker-compose.yaml rename to docker-compose.test.yaml index 7cd192c..7941afd 100644 --- a/docker-compose.yaml +++ b/docker-compose.test.yaml @@ -1,7 +1,6 @@ version: '3' services: addon: - image: "asosnovsky/shortumation:${ARCH:-amd64}-${BUILD_TAG:-latest}" volumes: - "./sample_config:/config" ports: