diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..7a39a8fb9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +# Virtual environments +.direnv +venv/ diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml new file mode 100644 index 000000000..4cfaba053 --- /dev/null +++ b/.github/workflows/docker-push.yml @@ -0,0 +1,28 @@ +name: Build and push digital-land-python to public ECR +on: + push: + branches: + # - main # TODO reinstate this before merge + - run-pipeline-commands-locally + +jobs: + build: + + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + python-version: 3.8 + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + - name: Build & Push + run: | + make docker-build + make docker-push + diff --git a/.gitignore b/.gitignore index 6cbda1836..3e1caed7e 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ var/cache ssl.pem var .junitxml +.envrc pyrightconfig.json .idea -.python-version \ No newline at end of file +.python-version diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..bf49c3e7d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM python:3.8 as digital-land-python + +RUN set -xe && \ + apt-get update && \ + apt-get install -y \ + awscli \ + time \ + gosu \ + make \ + git \ + gdal-bin \ + libspatialite-dev \ + libsqlite3-mod-spatialite + +WORKDIR /src +COPY . /src + +# Necessary to make sure the `digital-land` easyinstall entry script is found when invoking +# `digital-land` via shell from python space +ENV VIRTUAL_ENV=/opt/venv +RUN pip install --upgrade pip +RUN pip install virtualenv +RUN cd /opt && virtualenv venv --always-copy +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +RUN make init + +FROM digital-land-python as digital-land-specification + +RUN mkdir -p /collection +WORKDIR /collection +RUN set -ex; \ + wget https://github.com/digital-land/makerules/archive/refs/heads/run-all-pipeline-commands-locally-take-2.zip -O makerules.zip; \ + unzip makerules.zip; \ + make specification -f makerules-run-all-pipeline-commands-locally-take-2/makerules.mk +# TODO switch branch when merged +# wget https://github.com/digital-land/makerules/archive/refs/heads/main.zip -O makerules.zip; \ +# make specification -f makerules-main/makerules.mk + +FROM digital-land-specification as digital-land-pipeline + +WORKDIR /pipeline diff --git a/README.md b/README.md index c00f62edf..3dbceba8a 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,12 @@ Development requires Python 3.6.2 or later, we recommend using a [virtual enviro make python -m digital-land --help +There is also a docker image available on public ECR + +``` + docker run -it public.ecr.aws/l6z6v3j6/digital-land-python:latest digital-land +``` + ## Release procedure Update the tagged version number: diff --git a/makerules/python.mk b/makerules/python.mk index dc0908b0e..33cc5ae33 100644 --- a/makerules/python.mk +++ b/makerules/python.mk @@ -1,4 +1,9 @@ PIP_INSTALL_PACKAGE=[test] +ECR_REPO=public.ecr.aws/l6z6v3j6/ + +LAYER_NAME=digital-land-python +REPO_NAME=digital-land-python +ECR_PATH=$(ECR_REPO)$(REPO_NAME):$(LAYER_NAME) all:: lint test coverage @@ -45,3 +50,23 @@ upload:: dist makerules:: curl -qfsL '$(SOURCE_URL)/makerules/main/python.mk' > makerules/python.mk + +docker-build: docker-check + docker build . -t $(ECR_PATH) --target $(LAYER_NAME) + +docker-push: docker-check docker-ecr-login + docker push $(ECR_PATH) + +docker-pull: docker-check docker-ecr-login + docker pull $(ECR_PATH) + +docker-shell: docker-check docker-ecr-login + docker run -it $(ECR_PATH) bash + +docker-check: +ifeq (, $(shell which docker)) + $(error "No docker in $(PATH), consider doing apt-get install docker OR brew install --cask docker") +endif + +docker-ecr-login: + aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws