Skip to content

Commit

Permalink
Merge pull request #2 from f5devcentral/deploy
Browse files Browse the repository at this point in the history
errors. build
  • Loading branch information
kevin7s-io authored Apr 28, 2024
2 parents 6e39d76 + ad8a53d commit 3075eb0
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 5 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/lab-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: lab-build

on:
workflow_dispatch:
push:
branches:
- 'dev'
- 'main'
paths:
- labapp/**
tags:
- 'v*'
pull_request:
branches:
- 'dev'
paths:
- labapp/**
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/labapp
CONTEXT: labapp
jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
-
name: Login to Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:${{env.CONTEXT}}"
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
9 changes: 9 additions & 0 deletions labapp/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.git
.gitignore
Dockerfile*
docker-compose*
README.md
LICENSE
SUPPORT.md
.vscode
.github
9 changes: 9 additions & 0 deletions labapp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.10.14-slim
LABEL org.opencontainers.image.description MCN Practical Lab App

ENV PYTHONUNBUFFERED=1
WORKDIR /app
COPY app .
RUN pip install --no-cache-dir -r requirements.txt

CMD ["python", "./app.py"]
22 changes: 17 additions & 5 deletions labapp/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,31 @@
import requests
import markdown
import validators
import os
from dotenv import load_dotenv
from ce import get_ce_info, get_ce_state

app = Flask(__name__)
#app.config['ce_info'] = get_ce_info()
app.config['site'] = os.getenv('SITE', None)
info = None
if app.config['site']:
info = get_ce_info()
app.config['ce_info'] = info
app.config['ce_info'] = None
app.config['base_url'] = "lab-mcn.f5demos.com"
app.config['CACHE_TYPE'] = 'SimpleCache'
cache = Cache(app)
app.secret_key = "blahblahblah"

@app.errorhandler(400)
def return_400():
return render_template("error.html"), 400
@app.errorhandler(404)
@app.errorhandler(500)
def return_err(err):
"""common error handler"""
img = {
404: "/static/404.png",
500: "/static/500.png"
}
return render_template("error.html", err_img=img[err.code])

@app.route('/')
def index():
Expand Down Expand Up @@ -116,4 +128,4 @@ def make_request_ac1_azure():
return jsonify(status='fail', error=str(e))

if __name__ == '__main__':
app.run(debug=True)
app.run(debug=False)
Binary file added labapp/app/static/404.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added labapp/app/static/500.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions labapp/app/static/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ main {
overflow-y: auto;
}

.err {
display: flex;
justify-content: center; /* Centers horizontally */
align-items: center; /* Centers vertically */
height: 100vh; /* Full viewport height */
}

.err img {
display: block;
width: 100%; /* This will make the image responsive */
max-width: 600px; /* Maximum width of the image */
margin: 0 auto; /* Center the image */
}

.err p {
text-align: center; /* Center the text */
}

.left-aligned-button-container {
display: flex;
justify-content: flex-start; /* Aligns items to the left */
Expand Down
11 changes: 11 additions & 0 deletions labapp/app/templates/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}

{% block title %}MCN Practical Error{% endblock %}

{% block content %}
<div class="err">
<a href="/" class="d-flex align-items-center pb-3 mb-3 link-dark text-decoration-none border-bottom">
<img src="{{ err_img }}" alt="Descriptive Text">
</a>
</div>
{% endblock %}

0 comments on commit 3075eb0

Please sign in to comment.