From c743909767a03afecac06356c67df8c9a21886f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mih=C3=A1lik?= Date: Sat, 13 Apr 2024 20:15:36 +0200 Subject: [PATCH] WIP --- .github/workflows/deploy-development.yml | 18 ++++++++ .github/workflows/deploy-production.yml | 16 +++++++ .../{deploy.yml => deploy-testing.yml} | 6 +-- .github/workflows/main.yml | 4 +- .github/workflows/migrate-development.yml | 18 ++++++++ .github/workflows/migrate-production.yml | 0 .github/workflows/migrate-testing.yml | 0 .vscode/settings.json | 5 ++- Dockerfile | 2 - Pipfile | 3 +- Pipfile.lock | 44 +++++++++++-------- deployment/compose-development.yaml | 18 ++++++++ deployment/compose-production.yaml | 0 deployment/compose-testing.yaml | 15 +++++++ requirements.txt | 5 ++- webstrom/settings_development.py | 11 +++++ webstrom/settings_production.py | 0 webstrom/settings_testing.py | 7 +++ 18 files changed, 143 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/deploy-development.yml create mode 100644 .github/workflows/deploy-production.yml rename .github/workflows/{deploy.yml => deploy-testing.yml} (77%) create mode 100644 .github/workflows/migrate-development.yml create mode 100644 .github/workflows/migrate-production.yml create mode 100644 .github/workflows/migrate-testing.yml create mode 100644 deployment/compose-development.yaml create mode 100644 deployment/compose-production.yaml create mode 100644 deployment/compose-testing.yaml create mode 100644 webstrom/settings_development.py create mode 100644 webstrom/settings_production.py create mode 100644 webstrom/settings_testing.py diff --git a/.github/workflows/deploy-development.yml b/.github/workflows/deploy-development.yml new file mode 100644 index 00000000..4a452d7f --- /dev/null +++ b/.github/workflows/deploy-development.yml @@ -0,0 +1,18 @@ +name: Deploy Development + +on: + push: + branches: [ multiple-environments ] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: wshihadeh/docker-deployment-action@v2 + with: + remote_docker_host: webstrom@server.strom.sk + ssh_private_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PRIVATE_KEY }} + ssh_public_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PUBLIC_KEY }} + stack_file_name: deployment/compose-development.yaml + args: up --build --force-recreate --detach diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml new file mode 100644 index 00000000..5a7f4d68 --- /dev/null +++ b/.github/workflows/deploy-production.yml @@ -0,0 +1,16 @@ +name: Deploy Production + +on: workflow_dispatch + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: wshihadeh/docker-deployment-action@v2 + with: + remote_docker_host: webstrom@server.strom.sk + ssh_private_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PRIVATE_KEY }} + ssh_public_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PUBLIC_KEY }} + stack_file_name: deployment/compose-production.yaml + args: up --build --force-recreate --detach diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy-testing.yml similarity index 77% rename from .github/workflows/deploy.yml rename to .github/workflows/deploy-testing.yml index 4446fa95..15b91ad9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy-testing.yml @@ -1,4 +1,4 @@ -name: deploy +name: Deploy Testing on: workflow_dispatch @@ -6,11 +6,11 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: wshihadeh/docker-deployment-action@v2 with: remote_docker_host: webstrom@server.strom.sk ssh_private_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PRIVATE_KEY }} ssh_public_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PUBLIC_KEY }} - stack_file_name: compose.yaml + stack_file_name: deployment/compose-testing.yaml args: up --build --force-recreate --detach diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8192b463..13698a6b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Upgrade pip run: pip3 install --upgrade pip @@ -37,7 +37,7 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Upgrade pip run: pip3 install --upgrade pip diff --git a/.github/workflows/migrate-development.yml b/.github/workflows/migrate-development.yml new file mode 100644 index 00000000..33b4c4c0 --- /dev/null +++ b/.github/workflows/migrate-development.yml @@ -0,0 +1,18 @@ +name: Migrate Development + +on: + push: + branches: [ multiple-environments ] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: wshihadeh/docker-deployment-action@v2 + with: + remote_docker_host: webstrom@server.strom.sk + ssh_private_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PRIVATE_KEY }} + ssh_public_key: ${{ secrets.WEBSTROM_DEPLOY_SSH_PUBLIC_KEY }} + stack_file_name: deployment/compose-development.yaml + args: run webstrom-backend python manage.py migrate --noinput diff --git a/.github/workflows/migrate-production.yml b/.github/workflows/migrate-production.yml new file mode 100644 index 00000000..e69de29b diff --git a/.github/workflows/migrate-testing.yml b/.github/workflows/migrate-testing.yml new file mode 100644 index 00000000..e69de29b diff --git a/.vscode/settings.json b/.vscode/settings.json index 3784257a..05430d69 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,8 +6,11 @@ "editor.defaultFormatter": "ms-python.autopep8", "editor.formatOnSave": true, }, + "files.associations": { + "compose-*.yaml": "dockercompose" + }, "git.branchProtection": [ "master" ], "git.branchProtectionPrompt": "alwaysCommitToNewBranch" -} \ No newline at end of file +} diff --git a/Dockerfile b/Dockerfile index bbe44070..5db6d011 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,6 @@ RUN pipenv sync --dev --system COPY . /app -RUN python manage.py restoredb - EXPOSE 8000 ENTRYPOINT [ "daphne", "-b", "0.0.0.0", "-p", "8000", "webstrom.asgi:application" ] diff --git a/Pipfile b/Pipfile index 334e3e25..af6ccde4 100644 --- a/Pipfile +++ b/Pipfile @@ -6,12 +6,13 @@ name = "pypi" [packages] daphne = "~=4.0.0" dj-rest-auth = "~=5.0.1" -django = "~=3.2.23" +django = "~=4.2.11" django-allauth = "~=0.58.2" django-filter = "~=23.5" djangorestframework = "~=3.14.0" drf-writable-nested = "~=0.7.0" pillow = "~=10.3.0" +psycopg = "~=3.1.18" python-magic = "~=0.4.27" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 358d5aeb..994e7422 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "7df0459bbb2186ea13bb8c25ce90a415fc188092d1f00f88ca5d6350af79aa21" + "sha256": "9ad21e237de67487379a6de0311773509ba85f5d3532b9d175b886953783853b" }, "pipfile-spec": 6, "requires": {}, @@ -277,11 +277,11 @@ }, "django": { "hashes": [ - "sha256:7ca38a78654aee72378594d63e51636c04b8e28574f5505dff630895b5472777", - "sha256:a52ea7fcf280b16f7b739cec38fa6d3f8953a5456986944c3ca97e79882b4e38" + "sha256:6e6ff3db2d8dd0c986b4eec8554c8e4f919b5c1ff62a5b4390c17aff2ed6e5c4", + "sha256:ddc24a0a8280a0430baa37aff11f28574720af05888c62b7cfe71d219f4599d3" ], "index": "pypi", - "version": "==3.2.25" + "version": "==4.2.11" }, "django-allauth": { "hashes": [ @@ -418,6 +418,14 @@ "index": "pypi", "version": "==10.3.0" }, + "psycopg": { + "hashes": [ + "sha256:31144d3fb4c17d78094d9e579826f047d4af1da6a10427d91dfcfb6ecdf6f12b", + "sha256:4d5a0a5a8590906daa58ebd5f3cfc34091377354a1acced269dd10faf55da60e" + ], + "index": "pypi", + "version": "==3.1.18" + }, "pyasn1": { "hashes": [ "sha256:3a35ab2c4b5ef98e17dfdec8ab074046fbda76e281c5a706ccd82328cfc8f64c", @@ -507,11 +515,11 @@ }, "setuptools": { "hashes": [ - "sha256:659e902e587e77fab8212358f5b03977b5f0d18d4724310d4a093929fee4ca1a", - "sha256:b6df12d754b505e4ca283c61582d5578db83ae2f56a979b3bc9a8754705ae3bf" + "sha256:3b2dbd8f63dcc6b7c327d0243c2d7dc8c96cc507c016f09221f3787e6e528719", + "sha256:8d881f842bfc0e29e93bc98a2e650e8845609adff4d2989ba6c748e67b09d5be" ], "markers": "python_version >= '3.8'", - "version": "==69.4.0" + "version": "==69.5.0" }, "six": { "hashes": [ @@ -523,11 +531,11 @@ }, "sqlparse": { "hashes": [ - "sha256:5430a4fe2ac7d0f93e66f1efc6e1338a41884b7ddf2a350cedd20ccc4d9d28f3", - "sha256:d446183e84b8349fa3061f0fe7f06ca94ba65b426946ffebe6e3e8295332420c" + "sha256:714d0a4932c059d16189f58ef5411ec2287a4360f17cdd0edd2d09d4c5087c93", + "sha256:c204494cd97479d0e39f28c93d46c0b2d5959c7b9ab904762ea6c7af211c8663" ], - "markers": "python_version >= '3.5'", - "version": "==0.4.4" + "markers": "python_version >= '3.8'", + "version": "==0.5.0" }, "twisted": { "extras": [ @@ -760,11 +768,11 @@ }, "django": { "hashes": [ - "sha256:7ca38a78654aee72378594d63e51636c04b8e28574f5505dff630895b5472777", - "sha256:a52ea7fcf280b16f7b739cec38fa6d3f8953a5456986944c3ca97e79882b4e38" + "sha256:6e6ff3db2d8dd0c986b4eec8554c8e4f919b5c1ff62a5b4390c17aff2ed6e5c4", + "sha256:ddc24a0a8280a0430baa37aff11f28574720af05888c62b7cfe71d219f4599d3" ], "index": "pypi", - "version": "==3.2.25" + "version": "==4.2.11" }, "django-rest-swagger": { "hashes": [ @@ -1062,11 +1070,11 @@ }, "sqlparse": { "hashes": [ - "sha256:5430a4fe2ac7d0f93e66f1efc6e1338a41884b7ddf2a350cedd20ccc4d9d28f3", - "sha256:d446183e84b8349fa3061f0fe7f06ca94ba65b426946ffebe6e3e8295332420c" + "sha256:714d0a4932c059d16189f58ef5411ec2287a4360f17cdd0edd2d09d4c5087c93", + "sha256:c204494cd97479d0e39f28c93d46c0b2d5959c7b9ab904762ea6c7af211c8663" ], - "markers": "python_version >= '3.5'", - "version": "==0.4.4" + "markers": "python_version >= '3.8'", + "version": "==0.5.0" }, "tomlkit": { "hashes": [ diff --git a/deployment/compose-development.yaml b/deployment/compose-development.yaml new file mode 100644 index 00000000..e8043519 --- /dev/null +++ b/deployment/compose-development.yaml @@ -0,0 +1,18 @@ +version: "3" + +services: + webstrom-backend: + build: .. + + image: webstrom-backend-development + + environment: + - DJANGO_SETTINGS_MODULE=webstrom.settings_development + + volumes: + - /var/run/postgresql:/var/run/postgresql:rw + + restart: "always" + + ports: + - 8930:8000 diff --git a/deployment/compose-production.yaml b/deployment/compose-production.yaml new file mode 100644 index 00000000..e69de29b diff --git a/deployment/compose-testing.yaml b/deployment/compose-testing.yaml new file mode 100644 index 00000000..191e3724 --- /dev/null +++ b/deployment/compose-testing.yaml @@ -0,0 +1,15 @@ +version: "3" + +services: + webstrom-backend: + build: .. + + image: webstrom-backend-testing + + environment: + - DJANGO_SETTINGS_MODULE=webstrom.settings_testing + + restart: "always" + + ports: + - 8920:8000 diff --git a/requirements.txt b/requirements.txt index d53a229f..a7ba5c69 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ daphne==4.0.0 defusedxml==0.7.1 dill==0.3.8 dj-rest-auth==5.0.2 -Django==3.2.25 +Django==4.2.11 django-allauth==0.58.2 django-filter==23.5 django-rest-swagger==2.2.0 @@ -34,6 +34,7 @@ oauthlib==3.2.2 openapi-codec==1.3.2 pillow==10.3.0 platformdirs==4.2.0 +psycopg==3.1.18 pyasn1==0.6.0 pyasn1_modules==0.4.0 pycodestyle==2.11.1 @@ -51,7 +52,7 @@ requests-oauthlib==2.0.0 service-identity==24.1.0 simplejson==3.19.2 six==1.16.0 -sqlparse==0.4.4 +sqlparse==0.5.0 tomlkit==0.12.4 Twisted==24.3.0 txaio==23.1.1 diff --git a/webstrom/settings_development.py b/webstrom/settings_development.py new file mode 100644 index 00000000..81c07110 --- /dev/null +++ b/webstrom/settings_development.py @@ -0,0 +1,11 @@ +# pylint: disable=wildcard-import,unused-wildcard-import + +from .settings import * + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'webstrom-development', + 'USER': 'webstrom', + } +} diff --git a/webstrom/settings_production.py b/webstrom/settings_production.py new file mode 100644 index 00000000..e69de29b diff --git a/webstrom/settings_testing.py b/webstrom/settings_testing.py new file mode 100644 index 00000000..276308c4 --- /dev/null +++ b/webstrom/settings_testing.py @@ -0,0 +1,7 @@ +# pylint: disable=wildcard-import,unused-wildcard-import + +from .settings import * + +ALLOWED_HOSTS = [ + "localhost", +]