Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair Docker and Actions #50

Merged
merged 17 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/containerize-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Developer container builds

on:
push:

env:
IMAGE_NAME: freetakteam/ui:${{ github.sha }}
OC_REGISTRY: ghcr.io

jobs:

build:

runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- uses: actions/checkout@v4
- name: Build the container image
# can this be converted to podman at some point to be more foss?
run: docker build . --file Dockerfile --tag $OC_REGISTRY/$IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login $OC_REGISTRY -u $ --password-stdin

- name: Push image to registry
run: |
echo IMAGE_NAME=$IMAGE_NAME
docker push $OC_REGISTRY/$IMAGE_NAME

36 changes: 36 additions & 0 deletions .github/workflows/containerize-on-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Tag-triggered Containerization

on:
push:
tags:
- "*"

env:
IMAGE_BASE: freetakteam/ui
IMAGE_TAG: :${{ github.ref_name }}
OC_REGISTRY: ghcr.io

jobs:

build:

runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- uses: actions/checkout@v4
- name: Build the container image
# can this be converted to podman at some point to be more foss?
run: docker build . --file Dockerfile --tag $OC_REGISTRY/$IMAGE_BASE:$IMAGE_TAG --tag $OC_REGISTRY/$IMAGE_BASE:latest --label "runnumber=${GITHUB_RUN_ID}"

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login $OC_REGISTRY -u $ --password-stdin

- name: Push image to registry
run: |
echo IMAGE_BASE=$IMAGE_BASE
docker push $OC_REGISTRY/$IMAGE_BASE:$IMAGE_TAG
docker push $OC_REGISTRY/$IMAGE_BASE:latest

26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM python:3.11

RUN groupadd -r freetak && useradd -m -r -g freetak freetak

RUN mkdir -p /home/freetak/data && chown -R freetak:freetak /home/freetak/data && chmod 777 -R /home/freetak/data && chmod g+s /home/freetak/data
RUN ln -s /opt/FTSServer-UI.db /home/freetak/data/FTSServer-UI.db

USER freetak
WORKDIR /home/freetak

# Install pre-reqs then the base FTS
ENV PATH /home/freetak/.local/bin:/home/freetak/.local/lib:$PATH

COPY --chown=freetak:freetak --chmod=774 . ./
RUN pwd && ls

RUN pip install --no-cache-dir -r requirements.txt
RUN pip install -e .


# Provide a way to edit the configuration from outside the container
RUN mv /home/freetak/FreeTAKServer-UI/config.py /home/freetak/FreeTAKServer-UI/config.bak

EXPOSE 5000/tcp
VOLUME /home/freetak/data
CMD ["/home/freetak/docker-run.sh"]
21 changes: 10 additions & 11 deletions FreeTAKServer-UI/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,27 @@
"""

import os
from os import environ
from os import environ

class Config(object):

basedir = os.path.abspath(os.path.dirname(__file__))
class Config(object):
basedir = os.path.abspath(os.path.dirname(__file__))

SECRET_KEY = 'key'

# This will connect to the FTS db
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + '/opt/FTSServer-UI.db'

"""
experimental SSL support in the UI
"""
# experimental SSL support in the UI

# certificates path
# certpath = "/usr/local/lib/python3.8/dist-packages/FreeTAKServer/certs/"
# certpath = "/usr/local/lib/python3.8/dist-packages/FreeTAKServer/certs/"

# crt file path
# crtfilepath = f"{certpath}pubserver.pem"
# crtfilepath = f"{certpath}pubserver.pem"

# key file path
# keyfilepath = f"{certpath}pubserver.key.unencrypted"
# keyfilepath = f"{certpath}pubserver.key.unencrypted"

# this IP will be used to connect with the FTS API
IP = '127.0.0.1'
Expand Down Expand Up @@ -60,7 +59,7 @@ class Config(object):

# For 'in memory' database, please use:
# SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'

SQLALCHEMY_TRACK_MODIFICATIONS = False

# THEME SUPPORT
Expand Down Expand Up @@ -96,4 +95,4 @@ class DebugConfig(Config):
config_dict = {
'Production': ProductionConfig,
'Debug': DebugConfig
}
}
11 changes: 11 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
ftsui:
image: freetakserver-ui:latest
build:
context: ../UI/.
dockerfile: Dockerfile
# ports:
# - 5000:5000
volumes:
- ./ui-config:/home/freetak/data:Z
network_mode: "host"
37 changes: 37 additions & 0 deletions docker-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Detect and navigate to the python user site packages
# Some systems use `python3` instead of `python` so this is not entirely portable
cd "/home/freetak/FreeTAKServer-UI/" || raise error "Could not navigate to the user-sites path. Are you using a distro that requires python3 instead of python?"

# OBE as this is handled in the dockerfile, could be helpful in other kinds of deployments
# If config.py exists
#if test -f config.py; then
# Then we need to move it to a "backup"
# this way we can always give the user a new one if they delete theirs
# mv config.py config.bak
#fi

# Check if there is *NOT* a config.py in the shared volume
if [[ ! -f "/home/freetak/data/config.py" ]]
then
# If there isn't, then we need to give one to the user
cp config.bak /home/freetak/data/config.py
fi

# If the symlink has not been created yet, then we will do that
if [[ ! -f "config.py" ]]
then
ln -s /home/freetak/data/config.py config.py
fi

# TODO This can be implemented once the FTS-UI has an SSL operation mode
# Check if SSL certificates in the shared volumes exists
#if -n compgen -G "/home/freetak/data/*.crt" > /dev/null || compgen -G "/home/freetak/data/*.key" > /dev/null
# then
# generate some certs
# openssl req -x509 -newkey rsa:4096 -keyout autgenerated-key.pem -out autogenerated-cert.pem -sha256 -days 3650 -nodes -subj "/C=XX/ST=Unknown/L=Unknown/O=FreeTAKServer/OU=FTS-UI/CN=localhost"
#fi

# Now we can start the server
python run.py
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@
author_email='[email protected]',
description='an optional UI for FreeTAKServer',
install_requires = [
"flask",
"flask < 2.3",
"flask_login",
"flask_migrate",
"flask_wtf",
"WTForms == 2.3.3",
"sqlalchemy < 1.4",
"flask_sqlalchemy",
"email_validator",
"gunicorn",
"python-decouple",
"sqlalchemy-utils"
"sqlalchemy-utils",
"requests",
"eventlet"
],
include_package_data=True
)
)