1
0
Fork 0
forked from s3lph/matemat

Merge branch 'ci-deploy-staging' into DO-NOT-MERGE-horrible-webapp

This commit is contained in:
s3lph 2018-07-11 18:48:06 +02:00
commit d60331daf7
12 changed files with 37 additions and 25 deletions

View file

@ -1,10 +1,10 @@
--- ---
image: s3lph/matemat-ci:20180711-01 image: s3lph/matemat-ci:20180711-02
stages: stages:
- test - test
- codestyle - build
- deploy - staging
test: test:
stage: test stage: test
@ -14,15 +14,27 @@ test:
- sudo -u matemat python3-coverage report -m --include 'matemat/*' --omit '*/test_*.py' - sudo -u matemat python3-coverage report -m --include 'matemat/*' --omit '*/test_*.py'
codestyle: codestyle:
stage: codestyle stage: test
script: script:
- pip3 install -r requirements.txt - pip3 install -r requirements.txt
- sudo -u matemat pycodestyle matemat - sudo -u matemat pycodestyle matemat
# - sudo -u matemat mypy --ignore-missing-imports --strict -p matemat # - sudo -u matemat mypy --ignore-missing-imports --strict -p matemat
docker_build_push: build:
stage: deploy stage: build
script: script:
- docker build -t "registry.gitlab.com/s3lph/matemat:$(git rev-parse HEAD)" . - 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 login -u $CI_REGISTRY_USER -p $CI_REGISTRY_TOKEN registry.gitlab.com
- docker push "registry.gitlab.com/s3lph/matemat:$(git rev-parse HEAD)" - 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

View file

@ -12,6 +12,6 @@ RUN chown matemat:matemat -R /home/matemat
RUN pip3 install -r /home/matemat/requirements.txt RUN pip3 install -r /home/matemat/requirements.txt
WORKDIR /home/matemat WORKDIR /home/matemat
USER matemat # USER matemat
CMD python3 -m matemat CMD python3 -m matemat
EXPOSE 8080/tcp EXPOSE 8080/tcp

View file

@ -13,4 +13,4 @@ if __name__ == '__main__':
port = int(sys.argv[1]) port = int(sys.argv[1])
# Start the web server # Start the web server
MatematWebserver(port=port, staticroot='/var/matemat/upload').start() MatematWebserver(port=port, staticroot='./static').start()

View file

@ -78,8 +78,8 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No
if 'avatar' not in args: if 'avatar' not in args:
return return
avatar = bytes(args.avatar) avatar = bytes(args.avatar)
os.makedirs('/var/matemat/upload/thumbnails/users/', exist_ok=True) os.makedirs('./static/upload/thumbnails/users/', exist_ok=True)
with open(f'/var/matemat/upload/thumbnails/users/{user.id}.png', 'wb') as f: with open(f'./static/upload/thumbnails/users/{user.id}.png', 'wb') as f:
f.write(avatar) f.write(avatar)
except UnicodeDecodeError: 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) db.create_user(username, password, email, member=is_member, admin=is_admin)
elif change == 'newproduct': 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 return
name = str(args.name) name = str(args.name)
price_member = int(str(args.pricemember)) 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) newproduct = db.create_product(name, price_member, price_non_member)
if 'image' in args: if 'image' in args:
image = bytes(args.image) image = bytes(args.image)
os.makedirs('/var/matemat/upload/thumbnails/products/', exist_ok=True) os.makedirs('./static/upload/thumbnails/products/', exist_ok=True)
with open(f'/var/matemat/upload/thumbnails/products/{newproduct.id}.png', 'wb') as f: with open(f'./static/upload/thumbnails/products/{newproduct.id}.png', 'wb') as f:
f.write(image) f.write(image)
elif change == 'restock': elif change == 'restock':

View file

@ -47,7 +47,7 @@ def handle_change(args: RequestArguments, product: Product, db: MatematDatabase)
if change == 'del': if change == 'del':
db.delete_product(product) db.delete_product(product)
try: try:
os.remove(f'/var/matemat/upload/thumbnails/products/{product.id}.png') os.remove(f'./static/upload/thumbnails/products/{product.id}.png')
except FileNotFoundError: except FileNotFoundError:
pass pass
@ -76,6 +76,6 @@ def handle_change(args: RequestArguments, product: Product, db: MatematDatabase)
if 'image' in args: if 'image' in args:
image = bytes(args.image) image = bytes(args.image)
if len(image) > 0: if len(image) > 0:
os.makedirs('/var/matemat/upload/thumbnails/products/', exist_ok=True) os.makedirs('./static/upload/thumbnails/products/', exist_ok=True)
with open(f'/var/matemat/upload/thumbnails/products/{product.id}.png', 'wb') as f: with open(f'./static/upload/thumbnails/products/{product.id}.png', 'wb') as f:
f.write(image) f.write(image)

View file

@ -47,7 +47,7 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No
if change == 'del': if change == 'del':
db.delete_user(user) db.delete_user(user)
try: try:
os.remove(f'/var/matemat/upload/thumbnails/users/{user.id}.png') os.remove(f'./static/upload/thumbnails/users/{user.id}.png')
except FileNotFoundError: except FileNotFoundError:
pass pass
@ -83,6 +83,6 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No
if 'avatar' in args: if 'avatar' in args:
avatar = bytes(args.avatar) avatar = bytes(args.avatar)
if len(avatar) > 0: if len(avatar) > 0:
os.makedirs('/var/matemat/upload/thumbnails/users/', exist_ok=True) os.makedirs('./static/upload/thumbnails/users/', exist_ok=True)
with open(f'/var/matemat/upload/thumbnails/users/{user.id}.png', 'wb') as f: with open(f'./static/upload/thumbnails/users/{user.id}.png', 'wb') as f:
f.write(avatar) f.write(avatar)

View file

@ -22,7 +22,7 @@
<h2>Avatar</h2> <h2>Avatar</h2>
<form id="admin-avatar-form" method="post" action="/admin?change=avatar" enctype="multipart/form-data" accept-charset="UTF-8"> <form id="admin-avatar-form" method="post" action="/admin?change=avatar" enctype="multipart/form-data" accept-charset="UTF-8">
<img src="/img/thumbnails/users/{{ authuser.id }}.png" alt="Avatar of {{ authuser.name }}" /><br/> <img src="/upload/thumbnails/users/{{ authuser.id }}.png" alt="Avatar of {{ authuser.name }}" /><br/>
<label for="admin-avatar-avatar">Upload new file: </label> <label for="admin-avatar-avatar">Upload new file: </label>
<input id="admin-avatar-avatar" type="file" name="avatar" accept="image/png" /><br/> <input id="admin-avatar-avatar" type="file" name="avatar" accept="image/png" /><br/>

View file

@ -24,7 +24,7 @@
<input id="modproduct-balance" name="stock" type="text" value="{{ product.stock }}" /><br/> <input id="modproduct-balance" name="stock" type="text" value="{{ product.stock }}" /><br/>
<label for="modproduct-image"> <label for="modproduct-image">
<img height="150" src="/img/thumbnails/products/{{ product.id }}.png" alt="Image of {{ product.name }}" /> <img height="150" src="/upload/thumbnails/products/{{ product.id }}.png" alt="Image of {{ product.name }}" />
</label><br/> </label><br/>
<input id="modproduct-image" type="file" name="image" accept="image/png" /><br/> <input id="modproduct-image" type="file" name="image" accept="image/png" /><br/>

View file

@ -30,7 +30,7 @@
<input id="moduser-account-balance" name="balance" type="text" value="{{ user.balance }}" /><br/> <input id="moduser-account-balance" name="balance" type="text" value="{{ user.balance }}" /><br/>
<label for="moduser-account-avatar"> <label for="moduser-account-avatar">
<img height="150" src="/img/thumbnails/users/{{ user.id }}.png" alt="Avatar of {{ user.name }}" /> <img height="150" src="/upload/thumbnails/users/{{ user.id }}.png" alt="Avatar of {{ user.name }}" />
</label><br/> </label><br/>
<input id="moduser-account-avatar" type="file" name="avatar" accept="image/png" /><br/> <input id="moduser-account-avatar" type="file" name="avatar" accept="image/png" /><br/>

View file

@ -26,7 +26,7 @@ Your balance: {{ authuser.balance }}
{% endif %} {% endif %}
; Stock: {{ product.stock }}</span><br/> ; Stock: {{ product.stock }}</span><br/>
<div class="imgcontainer"> <div class="imgcontainer">
<img src="/img/thumbnails/products/{{ product.id }}.png" alt="Picture of {{ product.name }}" /> <img src="/upload/thumbnails/products/{{ product.id }}.png" alt="Picture of {{ product.name }}" />
</div> </div>
</a> </a>
</div> </div>

View file

@ -11,7 +11,7 @@
<a href="/touchkey?uid={{ user.id }}&username={{ user.name }}"> <a href="/touchkey?uid={{ user.id }}&username={{ user.name }}">
<span class="thumblist-title">{{ user.name }}</span><br/> <span class="thumblist-title">{{ user.name }}</span><br/>
<div class="imgcontainer"> <div class="imgcontainer">
<img src="/img/thumbnails/users/{{ user.id }}.png" alt="Avatar of {{ user.name }}" /> <img src="/upload/thumbnails/users/{{ user.id }}.png" alt="Avatar of {{ user.name }}" />
</div> </div>
</a> </a>
</div> </div>

View file

@ -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/db && chown matemat:matemat -R /var/matemat/db
RUN mkdir -p /var/matemat/upload && chown matemat:matemat -R /var/matemat/upload RUN mkdir -p /var/matemat/upload && chown matemat:matemat -R /var/matemat/upload
RUN apt-get update -qy 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 RUN pip3 install wheel pycodestyle mypy
WORKDIR /home/matemat WORKDIR /home/matemat