From fd2fdff8da318ac63dd74be01c7fe3110fdc36e9 Mon Sep 17 00:00:00 2001 From: Jerzy Spendel Date: Wed, 21 Jul 2021 16:01:17 +0200 Subject: [PATCH 1/6] Test commit --- .github/workflows/docker-build-test.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-build-test.yml b/.github/workflows/docker-build-test.yml index a2245c4c0e..ca5daecba0 100644 --- a/.github/workflows/docker-build-test.yml +++ b/.github/workflows/docker-build-test.yml @@ -14,6 +14,7 @@ on: push: branches: - dev + - dockerhub_ci_ecs pull_request: branches: - dev @@ -48,11 +49,11 @@ jobs: run: docker-compose -f docker/docker-compose.test.yml down - name: Save physionet image - if: github.ref == 'refs/heads/dev' || github.event.inputs.publish_tag + if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/dockerhub_ci_ecs' || github.event.inputs.publish_tag run: docker save physionet:latest | gzip > /tmp/physionet.tar.gz - name: Upload physionet image - if: github.ref == 'refs/heads/dev' || github.event.inputs.publish_tag + if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/dockerhub_ci_ecs' || github.event.inputs.publish_tag uses: actions/upload-artifact@v2 with: name: physionet @@ -60,7 +61,7 @@ jobs: publish: name: Publish to DockerHub - if: github.ref == 'refs/heads/dev' || github.event.inputs.publish_tag + if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/dockerhub_ci_ecs' || github.event.inputs.publish_tag environment: dockerhub runs-on: ubuntu-latest needs: build @@ -86,3 +87,14 @@ jobs: docker tag physionet:latest physionet/physionet:${{ github.event.inputs.publish_tag || 'latest' }} docker push physionet/physionet:${GITHUB_SHA} docker push physionet/physionet:${{ github.event.inputs.publish_tag || 'latest' }} + + - 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-2 + + - name: Update ECS + run: | + aws ecs describe-task-definition --task-definition physionet --query taskDefinition > task-definition.json From f679e84bd7c63a7ff100c2a70f004d32730a9349 Mon Sep 17 00:00:00 2001 From: Jerzy Spendel Date: Wed, 21 Jul 2021 18:57:03 +0200 Subject: [PATCH 2/6] Add deployment steps --- .github/workflows/docker-build-test.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/docker-build-test.yml b/.github/workflows/docker-build-test.yml index ca5daecba0..7f3affa89e 100644 --- a/.github/workflows/docker-build-test.yml +++ b/.github/workflows/docker-build-test.yml @@ -98,3 +98,19 @@ jobs: - name: Update ECS run: | aws ecs describe-task-definition --task-definition physionet --query taskDefinition > task-definition.json + + - name: Update ECS task definition + id: task-def + uses: aws-actions/amazon-ecs-render-task-definition@v1 + with: + task-definition: task-definition.json + container-name: physionet + image: physionet/physionet:${GITHUB_SHA} + + - name: Deploy task definition + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 + with: + task-definition: task-definition.json + service: physionet-service + cluster: physionet-cluster + wait-for-service-stability: true \ No newline at end of file From ac107f1a840d929ba6c63120ca93627b1bbbebc8 Mon Sep 17 00:00:00 2001 From: Jerzy Spendel Date: Fri, 23 Jul 2021 12:50:20 +0200 Subject: [PATCH 3/6] Split ECS part to another job --- .github/workflows/docker-build-test.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/docker-build-test.yml b/.github/workflows/docker-build-test.yml index 7f3affa89e..a6e7e99571 100644 --- a/.github/workflows/docker-build-test.yml +++ b/.github/workflows/docker-build-test.yml @@ -88,6 +88,13 @@ jobs: docker push physionet/physionet:${GITHUB_SHA} docker push physionet/physionet:${{ github.event.inputs.publish_tag || 'latest' }} + deploy_ecs: + name: Deploy ECS + needs: publish + environment: dockerhub + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/dockerhub_ci_ecs' + steps: - name: Configure aws credentials uses: aws-actions/configure-aws-credentials@v1 with: From 06b1caa1ba906394e810235d286c461691898909 Mon Sep 17 00:00:00 2001 From: Jerzy Spendel Date: Mon, 26 Jul 2021 15:16:41 +0200 Subject: [PATCH 4/6] Add whitenoise --- physionet-django/physionet/settings/base.py | 4 ++++ poetry.lock | 21 ++++++++++++++++----- pyproject.toml | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/physionet-django/physionet/settings/base.py b/physionet-django/physionet/settings/base.py index 9db5d8b452..b3a7a04162 100644 --- a/physionet-django/physionet/settings/base.py +++ b/physionet-django/physionet/settings/base.py @@ -33,6 +33,7 @@ # Application definition INSTALLED_APPS = [ + 'whitenoise.runserver_nostatic', 'dal', 'dal_select2', 'django.contrib.admin', @@ -58,6 +59,7 @@ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'physionet.middleware.maintenance.SystemMaintenanceMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -67,6 +69,8 @@ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] +STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage' + CRON_CLASSES = [ "physionet.cron.RemoveUnverifiedEmails", "physionet.cron.RemoveOutstandingInvites", diff --git a/poetry.lock b/poetry.lock index 32bafc18f8..f30dc1776a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -599,6 +599,17 @@ category = "main" optional = false python-versions = "*" +[[package]] +name = "whitenoise" +version = "5.3.0" +description = "Radically simplified static file serving for WSGI applications" +category = "main" +optional = false +python-versions = ">=3.5, <4" + +[package.extras] +brotli = ["brotli"] + [[package]] name = "zxcvbn-python" version = "4.4.24" @@ -610,7 +621,7 @@ python-versions = "*" [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "9c3fa03ed0f96de3e8e02802cacbb5808f2322d4839261f542c3db9e6d6dc8d4" +content-hash = "eed98f60b8d3b31b08783d8284ae354d2ca8080f7b31dbe5545af34e8f6acbf0" [metadata.files] bleach = [ @@ -899,13 +910,9 @@ protobuf = [ {file = "protobuf-3.17.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:2ae692bb6d1992afb6b74348e7bb648a75bb0d3565a3f5eea5bec8f62bd06d87"}, {file = "protobuf-3.17.3-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:99938f2a2d7ca6563c0ade0c5ca8982264c484fdecf418bd68e880a7ab5730b1"}, {file = "protobuf-3.17.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:6902a1e4b7a319ec611a7345ff81b6b004b36b0d2196ce7a748b3493da3d226d"}, - {file = "protobuf-3.17.3-cp38-cp38-win32.whl", hash = "sha256:59e5cf6b737c3a376932fbfb869043415f7c16a0cf176ab30a5bbc419cd709c1"}, - {file = "protobuf-3.17.3-cp38-cp38-win_amd64.whl", hash = "sha256:ebcb546f10069b56dc2e3da35e003a02076aaa377caf8530fe9789570984a8d2"}, {file = "protobuf-3.17.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:4ffbd23640bb7403574f7aff8368e2aeb2ec9a5c6306580be48ac59a6bac8bde"}, {file = "protobuf-3.17.3-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:26010f693b675ff5a1d0e1bdb17689b8b716a18709113288fead438703d45539"}, {file = "protobuf-3.17.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:e76d9686e088fece2450dbc7ee905f9be904e427341d289acbe9ad00b78ebd47"}, - {file = "protobuf-3.17.3-cp39-cp39-win32.whl", hash = "sha256:a38bac25f51c93e4be4092c88b2568b9f407c27217d3dd23c7a57fa522a17554"}, - {file = "protobuf-3.17.3-cp39-cp39-win_amd64.whl", hash = "sha256:85d6303e4adade2827e43c2b54114d9a6ea547b671cb63fafd5011dc47d0e13d"}, {file = "protobuf-3.17.3-py2.py3-none-any.whl", hash = "sha256:2bfb815216a9cd9faec52b16fd2bfa68437a44b67c56bee59bc3926522ecb04e"}, {file = "protobuf-3.17.3.tar.gz", hash = "sha256:72804ea5eaa9c22a090d2803813e280fb273b62d5ae497aaf3553d141c4fdd7b"}, ] @@ -1020,6 +1027,10 @@ webencodings = [ {file = "webencodings-0.5.1-py2.py3-none-any.whl", hash = "sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78"}, {file = "webencodings-0.5.1.tar.gz", hash = "sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923"}, ] +whitenoise = [ + {file = "whitenoise-5.3.0-py2.py3-none-any.whl", hash = "sha256:d963ef25639d1417e8a247be36e6aedd8c7c6f0a08adcb5a89146980a96b577c"}, + {file = "whitenoise-5.3.0.tar.gz", hash = "sha256:d234b871b52271ae7ed6d9da47ffe857c76568f11dd30e28e18c5869dbd11e12"}, +] zxcvbn-python = [ {file = "zxcvbn-python-4.4.24.tar.gz", hash = "sha256:900b28cc5e96be4091d8778f19f222832890264e338765a1c1c09fca2db64b2d"}, ] diff --git a/pyproject.toml b/pyproject.toml index ee0b5397f5..637e662b20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ psycopg2 = "~2.8.6" httplib2 = "^0.19.0" oauthlib = "^3.1.0" requests-oauthlib = "^1.3.0" +whitenoise = "^5.3.0" [tool.poetry.dev-dependencies] coverage = "^4.4.2" From 56039a4a3e78faf0a5e7f8c127cf29e131fca907 Mon Sep 17 00:00:00 2001 From: Jerzy Spendel Date: Mon, 26 Jul 2021 15:27:51 +0200 Subject: [PATCH 5/6] Add uwsgi config --- uwsgi.ini | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 uwsgi.ini diff --git a/uwsgi.ini b/uwsgi.ini new file mode 100644 index 0000000000..623b42e3be --- /dev/null +++ b/uwsgi.ini @@ -0,0 +1,4 @@ +[uwsgi] +http-socket = 0.0.0.0:8000 +module = physionet.wsgi:application +chdir = physionet-django \ No newline at end of file From bf44ff39cc61898550e70e98191b116aebef9a05 Mon Sep 17 00:00:00 2001 From: Jerzy Spendel Date: Mon, 26 Jul 2021 15:27:51 +0200 Subject: [PATCH 6/6] Add uwsgi config --- uwsgi.ini | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 uwsgi.ini diff --git a/uwsgi.ini b/uwsgi.ini new file mode 100644 index 0000000000..623b42e3be --- /dev/null +++ b/uwsgi.ini @@ -0,0 +1,4 @@ +[uwsgi] +http-socket = 0.0.0.0:8000 +module = physionet.wsgi:application +chdir = physionet-django \ No newline at end of file