From 8da58950adb605669ca3ffafa158a682dd952b82 Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 11 Jul 2018 16:46:05 +0200 Subject: [PATCH 1/9] Deployment image privileged once more... --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d70119d..c55d347 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,6 @@ RUN chown matemat:matemat -R /home/matemat RUN pip3 install -r /home/matemat/requirements.txt WORKDIR /home/matemat -USER matemat +# USER matemat CMD python3 -m matemat EXPOSE 8080/tcp From 68a228e95f651359de35fd2744b74623365f0579 Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 11 Jul 2018 16:57:38 +0200 Subject: [PATCH 2/9] Fixed user-generated static resources paths. --- matemat/__main__.py | 2 +- matemat/webserver/pagelets/admin.py | 8 ++++---- matemat/webserver/pagelets/modproduct.py | 6 +++--- matemat/webserver/pagelets/moduser.py | 6 +++--- templates/modproduct.html | 2 +- templates/moduser.html | 2 +- templates/productlist.html | 2 +- templates/userlist.html | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/matemat/__main__.py b/matemat/__main__.py index eef1fd5..579321a 100644 --- a/matemat/__main__.py +++ b/matemat/__main__.py @@ -13,4 +13,4 @@ if __name__ == '__main__': port = int(sys.argv[1]) # Start the web server - MatematWebserver(port=port, staticroot='/var/matemat/upload').start() + MatematWebserver(port=port, staticroot='./static').start() diff --git a/matemat/webserver/pagelets/admin.py b/matemat/webserver/pagelets/admin.py index f7e5ce8..412e194 100644 --- a/matemat/webserver/pagelets/admin.py +++ b/matemat/webserver/pagelets/admin.py @@ -78,8 +78,8 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No if 'avatar' not in args: return avatar = bytes(args.avatar) - os.makedirs('/var/matemat/upload/thumbnails/users/', exist_ok=True) - with open(f'/var/matemat/upload/thumbnails/users/{user.id}.png', 'wb') as f: + os.makedirs('./static/upload/thumbnails/users/', exist_ok=True) + with open(f'./static/upload/thumbnails/users/{user.id}.png', 'wb') as f: f.write(avatar) except UnicodeDecodeError: @@ -111,8 +111,8 @@ def handle_admin_change(args: RequestArguments, db: MatematDatabase): newproduct = db.create_product(name, price_member, price_non_member) if 'image' in args: image = bytes(args.image) - os.makedirs('/var/matemat/upload/thumbnails/products/', exist_ok=True) - with open(f'/var/matemat/upload/thumbnails/products/{newproduct.id}.png', 'wb') as f: + os.makedirs('./static/upload/thumbnails/products/', exist_ok=True) + with open(f'./static/upload/thumbnails/products/{newproduct.id}.png', 'wb') as f: f.write(image) elif change == 'restock': diff --git a/matemat/webserver/pagelets/modproduct.py b/matemat/webserver/pagelets/modproduct.py index c5938a4..7bd11b7 100644 --- a/matemat/webserver/pagelets/modproduct.py +++ b/matemat/webserver/pagelets/modproduct.py @@ -47,7 +47,7 @@ def handle_change(args: RequestArguments, product: Product, db: MatematDatabase) if change == 'del': db.delete_product(product) try: - os.remove(f'/var/matemat/upload/thumbnails/products/{product.id}.png') + os.remove(f'./static/upload/thumbnails/products/{product.id}.png') except FileNotFoundError: pass @@ -76,6 +76,6 @@ def handle_change(args: RequestArguments, product: Product, db: MatematDatabase) if 'image' in args: image = bytes(args.image) if len(image) > 0: - os.makedirs('/var/matemat/upload/thumbnails/products/', exist_ok=True) - with open(f'/var/matemat/upload/thumbnails/products/{product.id}.png', 'wb') as f: + os.makedirs('./static/upload/thumbnails/products/', exist_ok=True) + with open(f'./static/upload/thumbnails/products/{product.id}.png', 'wb') as f: f.write(image) diff --git a/matemat/webserver/pagelets/moduser.py b/matemat/webserver/pagelets/moduser.py index f385d56..b42342a 100644 --- a/matemat/webserver/pagelets/moduser.py +++ b/matemat/webserver/pagelets/moduser.py @@ -47,7 +47,7 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No if change == 'del': db.delete_user(user) try: - os.remove(f'/var/matemat/upload/thumbnails/users/{user.id}.png') + os.remove(f'./static/upload/thumbnails/users/{user.id}.png') except FileNotFoundError: pass @@ -83,6 +83,6 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No if 'avatar' in args: avatar = bytes(args.avatar) if len(avatar) > 0: - os.makedirs('/var/matemat/upload/thumbnails/users/', exist_ok=True) - with open(f'/var/matemat/upload/thumbnails/users/{user.id}.png', 'wb') as f: + os.makedirs('./static/upload/thumbnails/users/', exist_ok=True) + with open(f'./static/upload/thumbnails/users/{user.id}.png', 'wb') as f: f.write(avatar) diff --git a/templates/modproduct.html b/templates/modproduct.html index a5ee3e7..698790f 100644 --- a/templates/modproduct.html +++ b/templates/modproduct.html @@ -24,7 +24,7 @@


diff --git a/templates/moduser.html b/templates/moduser.html index a67b67e..e28ef82 100644 --- a/templates/moduser.html +++ b/templates/moduser.html @@ -30,7 +30,7 @@


diff --git a/templates/productlist.html b/templates/productlist.html index 4e4d7e0..6163de4 100644 --- a/templates/productlist.html +++ b/templates/productlist.html @@ -26,7 +26,7 @@ Your balance: {{ authuser.balance }} {% endif %} ; Stock: {{ product.stock }}
- Picture of {{ product.name }} + Picture of {{ product.name }}
diff --git a/templates/userlist.html b/templates/userlist.html index d1724f9..57717cc 100644 --- a/templates/userlist.html +++ b/templates/userlist.html @@ -11,7 +11,7 @@ {{ user.name }}
- Avatar of {{ user.name }} + Avatar of {{ user.name }}
From 69e08a70be3f9921b783d48f636a1366cf885741 Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 11 Jul 2018 17:17:00 +0200 Subject: [PATCH 3/9] Added a staging deployment CI job. --- .gitlab-ci.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2da70d5..566855e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,8 +3,8 @@ image: s3lph/matemat-ci:20180711-01 stages: - test -- codestyle -- deploy +- build +- staging test: stage: test @@ -14,15 +14,24 @@ test: - sudo -u matemat python3-coverage report -m --include 'matemat/*' --omit '*/test_*.py' codestyle: - stage: codestyle + stage: test script: - pip3 install -r requirements.txt - sudo -u matemat pycodestyle matemat # - sudo -u matemat mypy --ignore-missing-imports --strict -p matemat -docker_build_push: - stage: deploy +build: + stage: build script: - docker build -t "registry.gitlab.com/s3lph/matemat:$(git rev-parse HEAD)" . - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_TOKEN registry.gitlab.com - docker push "registry.gitlab.com/s3lph/matemat:$(git rev-parse HEAD)" + +staging: + stage: staging + script: + - ssh add - <<<"$STAGING_SSH_PRIVATE_KEY" + - echo "$(git rev-parse HEAD)" | ssh -p 20022 matemat@kernelpanic.lol + environment: + - name: staging + - url: https://matemat.kernelpanic.lol/ From 0f0eb0ac3bf1df8558e57c4756f1bee147f2f47a Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 11 Jul 2018 17:20:24 +0200 Subject: [PATCH 4/9] Fixed syntax error in Gitlab CI config. --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 566855e..98df15d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -33,5 +33,5 @@ staging: - ssh add - <<<"$STAGING_SSH_PRIVATE_KEY" - echo "$(git rev-parse HEAD)" | ssh -p 20022 matemat@kernelpanic.lol environment: - - name: staging - - url: https://matemat.kernelpanic.lol/ + name: staging + url: https://matemat.kernelpanic.lol/ From 1f9860a70788c69b7d704075b511aef92651a6fc Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 11 Jul 2018 17:34:59 +0200 Subject: [PATCH 5/9] Install a SSH client in the CI Docker image. --- .gitlab-ci.yml | 5 +++-- testing/Dockerfile | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 98df15d..6550324 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ --- -image: s3lph/matemat-ci:20180711-01 +image: s3lph/matemat-ci:20180711-02 stages: - test @@ -30,7 +30,8 @@ build: staging: stage: staging script: - - ssh add - <<<"$STAGING_SSH_PRIVATE_KEY" + - eval $(ssh-agent -s) + - ssh-add - <<<"$STAGING_SSH_PRIVATE_KEY" - echo "$(git rev-parse HEAD)" | ssh -p 20022 matemat@kernelpanic.lol environment: name: staging diff --git a/testing/Dockerfile b/testing/Dockerfile index a06b6ed..c51e01b 100644 --- a/testing/Dockerfile +++ b/testing/Dockerfile @@ -5,7 +5,7 @@ RUN useradd -d /home/matemat -m matemat RUN mkdir -p /var/matemat/db && chown matemat:matemat -R /var/matemat/db RUN mkdir -p /var/matemat/upload && chown matemat:matemat -R /var/matemat/upload RUN apt-get update -qy -RUN apt-get install -y --no-install-recommends sudo git docker.io python3-dev python3-pip python3-coverage python3-setuptools build-essential +RUN apt-get install -y --no-install-recommends sudo openssh-client git docker.io python3-dev python3-pip python3-coverage python3-setuptools build-essential RUN pip3 install wheel pycodestyle mypy WORKDIR /home/matemat From 66dd02fcddeae747efbb3c278413d79be47ac10e Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 11 Jul 2018 17:37:48 +0200 Subject: [PATCH 6/9] Limited "staging" stage to only run on ci-deploy-staging. --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6550324..f6caf66 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -36,3 +36,5 @@ staging: environment: name: staging url: https://matemat.kernelpanic.lol/ + only: + - ci-deploy-staging \ No newline at end of file From 355900e4976fb7a93e3524e0aacd51d1a4b50819 Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 11 Jul 2018 17:55:48 +0200 Subject: [PATCH 7/9] Disabled host key checking in the deployment CI job. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f6caf66..609f810 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -32,7 +32,7 @@ staging: script: - eval $(ssh-agent -s) - ssh-add - <<<"$STAGING_SSH_PRIVATE_KEY" - - echo "$(git rev-parse HEAD)" | ssh -p 20022 matemat@kernelpanic.lol + - echo "$(git rev-parse HEAD)" | ssh -p 20022 -oStrictHostKeyChecking=no matemat@kernelpanic.lol environment: name: staging url: https://matemat.kernelpanic.lol/ From 1ab69f1307466ac201fa5ad459d3e3a5b42776f5 Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 11 Jul 2018 18:23:34 +0200 Subject: [PATCH 8/9] Fixed a wrong path missed earlier. --- templates/admin_all.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/admin_all.html b/templates/admin_all.html index 2c24de8..b977987 100644 --- a/templates/admin_all.html +++ b/templates/admin_all.html @@ -22,7 +22,7 @@

Avatar

- Avatar of {{ authuser.name }}
+ Avatar of {{ authuser.name }}

From f860ae3b58b8701e6391a50048d914f3168407a5 Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 11 Jul 2018 18:24:23 +0200 Subject: [PATCH 9/9] Fixed: Wrong argument name check when adding a new product. --- matemat/webserver/pagelets/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matemat/webserver/pagelets/admin.py b/matemat/webserver/pagelets/admin.py index 412e194..1caab25 100644 --- a/matemat/webserver/pagelets/admin.py +++ b/matemat/webserver/pagelets/admin.py @@ -103,7 +103,7 @@ def handle_admin_change(args: RequestArguments, db: MatematDatabase): db.create_user(username, password, email, member=is_member, admin=is_admin) elif change == 'newproduct': - if 'name' not in args or 'price_member' not in args or 'price_non_member' not in args: + if 'name' not in args or 'pricemember' not in args or 'pricenonmember' not in args: return name = str(args.name) price_member = int(str(args.pricemember))