diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2da70d5..1c614c1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,10 +1,10 @@ --- -image: s3lph/matemat-ci:20180711-01 +image: s3lph/matemat-ci:20180711-02 stages: - test -- codestyle -- deploy +- build +- staging test: stage: test @@ -14,15 +14,27 @@ 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: + - eval $(ssh-agent -s) + - ssh-add - <<<"$STAGING_SSH_PRIVATE_KEY" + - echo "$(git rev-parse HEAD)" | ssh -p 20022 -oStrictHostKeyChecking=no matemat@kernelpanic.lol + environment: + name: staging + url: https://matemat.kernelpanic.lol/ + only: + - DO-NOT-MERGE-horrible-webapp \ No newline at end of file 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 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..1caab25 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: @@ -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)) @@ -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/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 }}

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 }}
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