From b3b12638ad85fe1b3744561a2220d255cf9e105c Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 13 May 2024 21:02:41 +0930 Subject: [PATCH] feat: Build docker container for release !1 --- .dockerignore | 12 ++++++++++++ .gitlab-ci.yml | 35 ++++++++++++++++++++++++++++++++++- CONTRIBUTING.md | 15 ++++++++++++++- dockerfile | 21 +++++++++++++++++++++ 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..45ae160a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +.git +.git* +website-template/ +gitlab-ci/ +venv/ +docs/ +**/*.sqlite3 +**/static/ +__pycache__ +**__pycache__ +**.pyc +** .pytest* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 82e5468c..3b01511d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,8 +4,19 @@ variables: MY_PROJECT_ID: "57560288" # GIT_SYNC_URL: "https://$GITHUB_USERNAME_ROBOT:$GITHUB_TOKEN_ROBOT@github.com/NoFussComputing/.git" + # Docker Build / Publish + DOCKER_IMAGE_BUILD_TARGET_PLATFORMS: "linux/amd64,linux/arm64" + DOCKER_IMAGE_BUILD_NAME: django-template + DOCKER_IMAGE_BUILD_REGISTRY: $CI_REGISTRY_IMAGE + DOCKER_IMAGE_BUILD_TAG: $CI_COMMIT_SHA + + # Docker Publish + DOCKER_IMAGE_PUBLISH_NAME: django-template + DOCKER_IMAGE_PUBLISH_REGISTRY: docker.io/nofusscomputing + DOCKER_IMAGE_PUBLISH_URL: https://hub.docker.com/r/nofusscomputing/$DOCKER_IMAGE_PUBLISH_NAME + # Docs NFC - PAGES_ENVIRONMENT_PATH: projects/itsm/ + PAGES_ENVIRONMENT_PATH: projects/django-template/ # RELEASE_ADDITIONAL_ACTIONS_BUMP: ./.gitlab/additional_actions_bump.sh @@ -18,3 +29,25 @@ include: file: - .gitlab-ci_common.yaml - template/automagic.gitlab-ci.yaml + + +Website.Submodule.Deploy: + extends: .submodule_update_trigger + variables: + SUBMODULE_UPDATE_TRIGGER_PROJECT: nofusscomputing/infrastructure/website + environment: + url: https://nofusscomputing.com/$PAGES_ENVIRONMENT_PATH + name: Documentation + rules: + - if: # condition_dev_branch_push + $CI_COMMIT_BRANCH == "development" && + $CI_PIPELINE_SOURCE == "push" + exists: + - '{docs/**,pages/**}/*.md' + changes: + paths: + - '{docs/**,pages/**}/*.md' + compare_to: 'master' + when: always + + - when: never diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 825a6b81..393621f6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,7 +19,7 @@ To setup the django test server run the following ``` bash -cd itsm +cd app python manage.py runserver 8002 @@ -43,3 +43,16 @@ test can be run by running the following: 1. `pytest --cov --cov-report html --cov=./` + +## Docker Container + +``` bash + +cd app + +docker build . --tag django-app:dev + +docker run -d --rm -v ${PWD}/db.sqlite3:/app/db.sqlite3 -p 8002:8000 --name app django-app:dev + +``` + diff --git a/dockerfile b/dockerfile new file mode 100644 index 00000000..e05470a9 --- /dev/null +++ b/dockerfile @@ -0,0 +1,21 @@ +FROM python:3.11-alpine3.19 + + +COPY requirements.txt requirements.txt +COPY requirements_test.txt requirements_test.txt + + +COPY ./app/. app + + +RUN pip install --no-cache-dir -r requirements.txt; \ + python /app/manage.py collectstatic --noinput + + +WORKDIR /app + + +EXPOSE 8000 + + +CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]