diff --git a/.circleci/config.yml b/.circleci/config.yml index 3c3bc8763..d96ac4543 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,36 +1,64 @@ -version: 2.1 +executors: + docker-publisher: + machine: true jobs: - setup-lint-test: - docker: - - image: circleci/python:latest + build: + executor: docker-publisher steps: - checkout - - restore_cache: - keys: - - deps-{{ checksum "pyproject.toml" }} - run: - command: ./ci/setup.sh - name: Setup - - save_cache: - key: deps-{{ checksum "pyproject.toml" }} + command: ./build-dist-wheel.sh + name: Build Python Wheel + - store_test_results: + path: test-results/pytest + - store_artifacts: + path: test-results/coverage + - run: + command: ./build-runnable-image.sh + name: Build Runnable Docker Image + - run: + command: ./ci/archive-image.sh ./<< pipeline.parameters.image_archive >> + name: Archive Docker image + - persist_to_workspace: paths: - - /home/circleci/project/.poetry/virtualenvs + - ./<< pipeline.parameters.image_archive >> + - ./dist + - ./docker-env + - ./ci/tag-and-push.sh + root: . + deploy: + executor: docker-publisher + steps: + - attach_workspace: + at: . - run: - command: ./lint.sh - name: Lint + command: docker load -i "./<< pipeline.parameters.image_archive >>" + name: Load archive Docker image - run: - command: ./test.sh - name: Test - - store_test_results: - path: test-results + command: ./ci/tag-and-push.sh + name: Publish Docker Image to Docker Hub +parameters: + image_archive: + default: image.tar + type: string +version: 2.1 workflows: - version: 2.1 main: jobs: - setup-lint-test: - - filters: + - build: + filters: branches: only: - release - develop - circleci + - deploy: + filters: + branches: + only: + - release + - circleci + requires: + - build + version: 2.1 + diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 000000000..a955c5383 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,5 @@ +{ + "trailingComma": "es5", + "arrowParens": "always", + "tabWidth": 2 +} diff --git a/Dockerfile b/Dockerfile index 89d8c02ac..aeb53977a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM python:alpine AS codex-install +ARG BASE_VERSION +FROM ajslater/python-alpine:$BASE_VERSION AS codex-install RUN echo "**** install system wheel building packages ****" && \ apk add --no-cache \ @@ -17,14 +18,8 @@ RUN pip3 install wheel COPY dist/*.whl /tmp/ RUN pip3 wheel /tmp/*.whl --wheel-dir=/wheels -FROM python:alpine - -RUN echo "*** UID/GID Init. TODO move to a base image ***" -RUN apk add --no-cache shadow -RUN echo "*** create default user ***" && \ - adduser --uid 911 --home /config --shell /bin/false --disabled-password abc && \ - usermod -G users abc -COPY docker/usr/local/sbin/*.sh /usr/local/sbin/ +FROM ajslater/python-alpine:$BASE_VERSION +LABEL version python${BASE_VERSION}_codex-${PKG_VERSION} RUN echo "*** install system runtime packages ***" && \ apk add --no-cache \ @@ -44,5 +39,4 @@ RUN pip3 install --no-index --find-links=/wheels /wheels/codex*.whl VOLUME /comics VOLUME /config EXPOSE 9810 -ENTRYPOINT ["/usr/local/sbin/entrypoint.sh"] CMD ["/usr/local/bin/codex"] diff --git a/Dockerfile.build b/Dockerfile.build index 127e9e0a2..6e98c05e5 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -1,47 +1,35 @@ -FROM ubuntu:focal +FROM ajslater/codex-builder:focal_1.0.0-db5d3fe ARG DEBIAN_FRONTEND=noninteractive -RUN echo "*** install system build dependencies ***" -WORKDIR /app -RUN apt-get update && apt-get install -y \ - gnupg2 \ - ca-certificates -COPY docker/nodesource/nodesource.focal.list /etc/apt/sources.list.d/ -COPY docker/nodesource/nodesource.gpg.key . -RUN apt-key add ./nodesource.gpg.key -RUN apt-get update && apt-get install -y \ - build-essential \ - nodejs \ - libffi-dev \ - libjpeg-dev \ - libssl-dev \ - libwebp-dev \ - libyaml-dev \ - python3-pip \ - python3-venv \ - zlib1g-dev - -RUN echo "*** install poetry ***" && \ - pip3 install -U poetry +############# +# APP SETUP # +############# RUN echo "**** copying source for dev build ****" COPY . . -RUN echo "*** install API build dependencies ***" && \ - poetry install --no-root --no-dev +RUN ./setup-dev.sh -WORKDIR /app/frontend -RUN echo "*** install frontend build dependencies ***" && \ - npm install +######## +# TEST # +######## + +WORKDIR /app +RUN echo "*** run lint ***" +RUN ./lint.sh -RUN echo "*** copy choices from frontend ***" && \ - cp src/choices/* ../codex/choices/ +RUN echo "*** run tests ***" +RUN ./test.sh -# WORKDIR /app -# RUN echo "*** run tests ***" -# RUN ./test.sh -# WORKDIR /app/frontend +VOLUME /test-results +RUN cp -a test-results/* /test-results + +######### +# BUILD # +######### + +WORKDIR /app/frontend RUN echo "*** build frontend ***" && \ rm -rf ../codex/static_build && \ diff --git a/README.md b/README.md index 06b29390c..ff1e594bf 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Codex is a comic archive browser and reader. ## State of Development Codex is in alpha test. It has not received widespread testing. -[Please file bug reports on GitHub.](https://github.com/ajslater/codex/issues) +[Please file bug reports on GitHub.](https://github.com/ajslater/codex/issues) It is still possible that the data model might change enough that subsequent versions might require a database reset. ## Demonstration @@ -173,6 +173,7 @@ Specify a reverse proxy sub path (if you have one) in the config/hypercorn.toml ```toml root_path = "/codex" + ``` #### Nginx Reverse Proxy 502 when container is refreshed. diff --git a/build-wheel.sh b/build-dist-wheel.sh similarity index 100% rename from build-wheel.sh rename to build-dist-wheel.sh diff --git a/build-docker-image.sh b/build-docker-image.sh deleted file mode 100755 index ea50f8ec3..000000000 --- a/build-docker-image.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -# Build a codex docker image suitable for running from Dockerfile -docker-compose build diff --git a/build-runnable-image.sh b/build-runnable-image.sh new file mode 100755 index 000000000..32f1125d0 --- /dev/null +++ b/build-runnable-image.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# Build a codex docker image suitable for running from Dockerfile +. ./docker-env +docker build -t "$IMAGE" --build-arg "BASE_VERSION=$BASE_VERSION" --build-arg "PKG_VERSION=$PKG_VERSION" . diff --git a/ci/archive-image.sh b/ci/archive-image.sh new file mode 100755 index 000000000..b2007fafd --- /dev/null +++ b/ci/archive-image.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -euo pipefail +source ./docker-env +docker save -o "$1" "$IMAGE" diff --git a/ci/setup.sh b/ci/setup.sh deleted file mode 100755 index 50bc935c4..000000000 --- a/ci/setup.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -# setup script for circleci -set -xeuo pipefail -# TODO Could speed up ci by replacing this with an image - -if [ -n "$CIRCLE_BRANCH" ]; then - sudo apt-get install -y \ - gnupg2 \ - ca-certificates - sudo cp docker/nodesource/nodesource.buster.list /etc/apt/sources.list.d/ - sudo apt-key add ./docker/nodesource/nodesource.gpg.key - sudo apt-get update - sudo apt-get install -y \ - build-essential \ - libffi-dev \ - libjpeg-dev \ - libssl-dev \ - libyaml-dev \ - nodejs \ - python3-pip \ - python3-venv \ - shellcheck \ - zlib1g-dev -fi - -pip3 install -U poetry -poetry update -sudo npm install -g prettier -bash -c "cd frontend && npm install --no-optional" -cp frontend/src/choices/* codex/choices/ diff --git a/ci/tag-and-push.sh b/ci/tag-and-push.sh new file mode 100755 index 000000000..3b4eb5471 --- /dev/null +++ b/ci/tag-and-push.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -euo pipefail +source ./docker-env +VERSION=python${BASE_VERSION}_mylar-${PKG_VERSION} +TAG=$VERSION-$(echo "$CIRCLE_SHA1" | head -c 7) +docker tag "$IMAGE" "$IMAGE:$TAG" +docker tag "$IMAGE" "$IMAGE:latest" +docker login -u="$DOCKER_USER" -p="$DOCKER_PASS" +docker push "$REPO" diff --git a/copy-dist.sh b/copy-dist.sh deleted file mode 100755 index 35041368f..000000000 --- a/copy-dist.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -cp /app/dist/* /dist/ diff --git a/docker-compose-build.yaml b/docker-compose-build.yaml index a2080ecfc..00477d12c 100644 --- a/docker-compose-build.yaml +++ b/docker-compose-build.yaml @@ -9,3 +9,4 @@ services: container_name: codex-builder volumes: - ./dist/:/dist/ + - ./test-results/:/app/test-results/ diff --git a/docker-env b/docker-env index 62c8fffa8..0e58b7777 100644 --- a/docker-env +++ b/docker-env @@ -1,2 +1,6 @@ +REPO=ajslater/codex +IMAGE=ajslater/codex +BASE_VERSION=latest +PKG_VERSION=v0.5.0 PUID=501 PGID=20 diff --git a/docker/usr/local/sbin/entrypoint.sh b/docker/usr/local/sbin/entrypoint.sh deleted file mode 100755 index dbec6ffe7..000000000 --- a/docker/usr/local/sbin/entrypoint.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -set -eu -if [ -n "${PUID:-}${PGID:-}" ]; then - /usr/local/sbin/moduser.sh - su abc --shell /bin/sh --command "$@" -else - exec "$@" -fi diff --git a/docker/usr/local/sbin/moduser.sh b/docker/usr/local/sbin/moduser.sh deleted file mode 100755 index 3d3fff946..000000000 --- a/docker/usr/local/sbin/moduser.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -set -eu -PUID=${PUID:-911} -PGID=${PGID:-911} - -groupmod --non-unique --gid "$PGID" abc -usermod --non-unique --uid "$PUID" abc - -echo " -User uid: $(id -u abc) -User gid: $(id -g abc) -------------------------------------- -" -chown abc:abc /config -chown abc:abc /comics diff --git a/frontend/src/browser.vue b/frontend/src/browser.vue index e2979bc21..9dbf6c373 100644 --- a/frontend/src/browser.vue +++ b/frontend/src/browser.vue @@ -22,9 +22,7 @@ >