From 203deee66c0773d53d821ed53568093b0c031d88 Mon Sep 17 00:00:00 2001 From: Tessa Alexander <1619343+asset-web@users.noreply.github.com> Date: Mon, 21 Aug 2023 14:03:39 +0100 Subject: [PATCH] WIP: TMMA: 440 Build dev Docker environment (#203) * TMMA-440: Extend Docker base image with Python enhancements * Add a basic docker build GitHub action CI/CD check --- .github/workflows/docker.yml | 39 ++++++++++++++++++++++++++++++++++++ deploy/Dockerfile | 9 ++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..418d8502 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,39 @@ +name: Docker build +# TODO: Trigger a fresh build every Wednesday +# Triggered after changes to code or deployment config for model 1 +# Or can be triggered manualy +on: + workflow_dispatch: + push: + paths: + # TODO: Review scope of GitHub action grows + - '.github/workflows/docker.yml' + - 'deploy/Dockerfile' + - 'entrypoints/**' + - 'requirements/**' + # schedule: + # - cron: 30 9 * * WED + +env: + IMAGE_NAME: uobristol/temmpo-web + +jobs: + build: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: Record Docker version + run: docker -v + - uses: whoan/docker-build-with-cache-action@v6 + with: + context: . + dockerfile: 'deploy/Dockerfile' + username: ${{ secrets.DOCKER_HUB_USER }} + password: "${{ secrets.DOCKER_HUB_PASSWORD }}" + image_name: ${{ env.IMAGE_NAME }} + image_tag: ${{ github.sha }} + # Build from scratch if a scheduled job + pull_image_and_stages: ${{ github.event_name != 'schedule' }} + push_image_and_stages: docker run ${{ env.IMAGE_NAME }}:${{ github.sha }} + +# https://github.com/marketplace/actions/build-docker-images-using-cache#from-a-compose-file \ No newline at end of file diff --git a/deploy/Dockerfile b/deploy/Dockerfile index 26c24e30..ff8cb8aa 100644 --- a/deploy/Dockerfile +++ b/deploy/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.8.17-slim +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 ENV PIP_VERSION='23.2.1' ENV SETUPTOOLS_VERSION='68.0.0' ENV PIP_TOOLS_VERSION='7.2.0' @@ -40,4 +42,9 @@ RUN pip install virtualenv==$VE_VERSION WORKDIR /srv -VOLUME [ "/srv" ] \ No newline at end of file +VOLUME [ "/srv" ] + +# TODO: Replace temp basic build test as image is developed further +COPY requirements/requirements.txt /srv +RUN pip install --no-deps -r /srv/requirements.txt +CMD [ "pip", "check" ] \ No newline at end of file