1
0
mirror of https://github.com/gilbN/theme.park.git synced 2024-11-20 01:52:32 +01:00
This commit is contained in:
GilbN 2022-03-22 09:06:13 +00:00
parent 217f7153d0
commit 4848e6cb56
7 changed files with 82 additions and 85 deletions

View File

@ -2,7 +2,10 @@ name: docker build
on: on:
release: release:
types: types:
- published - released
push:
branches:
- develop
jobs: jobs:
push_to_ghcr_io: push_to_ghcr_io:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -11,7 +14,6 @@ jobs:
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
fetch-depth: 0 fetch-depth: 0
ref: ${{ github.event.release.target_commitish }}
- name: Get the version - name: Get the version
id: get_version id: get_version
run: echo ::set-output name=VERSION::${{ github.event.release.tag_name }} run: echo ::set-output name=VERSION::${{ github.event.release.tag_name }}
@ -24,15 +26,15 @@ jobs:
registry: ghcr.io registry: ghcr.io
username: ${{ github.repository_owner }} username: ${{ github.repository_owner }}
password: ${{ secrets.GH_PAT }} password: ${{ secrets.GH_PAT }}
- name: build&push live - name: build&push master
if: ${{ github.event.release.target_commitish == 'live' }} if: ${{ github.event.release.target_commitish == 'live' }}
run: | run: |
docker build docker/ --build-arg TP_RELEASE=${{ steps.get_version.outputs.VERSION }} --build-arg BUILD_DATE=${{ steps.date_time.outputs.NOW }} --tag ghcr.io/gilbn/theme.park --tag ghcr.io/gilbn/theme.park:${{ steps.get_version.outputs.VERSION }} docker build --build-arg TP_RELEASE=${{ steps.get_version.outputs.VERSION }} --build-arg BUILD_DATE=${{ steps.date_time.outputs.NOW }} --tag ghcr.io/gilbn/theme.park --tag ghcr.io/gilbn/theme.park:${{ steps.get_version.outputs.VERSION }}
docker push ghcr.io/gilbn/theme.park docker push ghcr.io/gilbn/theme.park
- name: build&push dev - name: build&push develop
if: ${{ github.event.release.target_commitish == 'live_develop' }} if: ${{ github.ref == 'refs/heads/develop' }}
run: | run: |
docker build docker/ --build-arg TP_RELEASE=${{ steps.get_version.outputs.VERSION }} --build-arg BUILD_DATE=${{ steps.date_time.outputs.NOW }} --tag ghcr.io/gilbn/theme.park:develop --tag ghcr.io/gilbn/theme.park:${{ steps.get_version.outputs.VERSION }} docker build --build-arg TP_RELEASE=${{ steps.get_version.outputs.VERSION }} --build-arg BUILD_DATE=${{ steps.date_time.outputs.NOW }} --tag ghcr.io/gilbn/theme.park:develop }}
docker push --all-tags ghcr.io/gilbn/theme.park docker push --all-tags ghcr.io/gilbn/theme.park
push_to_dockerhub: push_to_dockerhub:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -52,14 +54,14 @@ jobs:
with: with:
username: ${{ secrets.DH_USER }} username: ${{ secrets.DH_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: build&push dh live - name: build&push dh master
if: ${{ github.event.release.target_commitish == 'live' }} if: ${{ github.event.release.target_commitish == 'live' }}
run: | run: |
docker build docker/ --build-arg TP_RELEASE=${{ steps.get_version.outputs.VERSION }} --build-arg BUILD_DATE=${{ steps.date_time.outputs.NOW }} --tag ghcr.io/gilbn/theme.park --tag ghcr.io/gilbn/theme.park:${{ steps.get_version.outputs.VERSION }} docker build --build-arg TP_RELEASE=${{ steps.get_version.outputs.VERSION }} --build-arg BUILD_DATE=${{ steps.date_time.outputs.NOW }} --tag ghcr.io/gilbn/theme.park --tag gilbn/theme.park:${{ steps.get_version.outputs.VERSION }}
docker push ghcr.io/gilbn/theme.park docker push gilbn/theme.park
- name: build&push dh dev - name: build&push dh develop
if: ${{ github.event.release.target_commitish == 'live_develop' }} if: ${{ github.ref == 'refs/heads/develop' }}
run: | run: |
docker build docker/ --build-arg TP_RELEASE=${{ steps.get_version.outputs.VERSION }} --build-arg BUILD_DATE=${{ steps.date_time.outputs.NOW }} --tag gilbn/theme.park:develop --tag gilbn/theme.park:${{ steps.get_version.outputs.VERSION }} docker build --build-arg TP_RELEASE=${{ steps.get_version.outputs.VERSION }} --build-arg BUILD_DATE=${{ steps.date_time.outputs.NOW }} --tag gilbn/theme.park:develop --tag }}
docker push --all-tags gilbn/theme.park docker push --all-tags gilbn/theme.park

23
Dockerfile Normal file
View File

@ -0,0 +1,23 @@
FROM ghcr.io/linuxserver/baseimage-alpine-nginx:3.14
# set version label
ARG BUILD_DATE
ARG TP_RELEASE
LABEL build_version="Version:- ${VERSION} Build-date:- ${BUILD_DATE}"
LABEL maintainer="gilbn"
RUN \
echo " ## Installing packages ## " && \
apk add --no-cache --virtual=build-dependencies \
python3 \
curl && \
echo "**** install theme.park ****" && \
mkdir -p /app/themepark
# copy local files
WORKDIR /app
COPY css/ /app/themepark/css/
COPY resources/ /app/themepark/resources/
COPY themes.py index.html /app/themepark/
COPY docker/root/ /

View File

@ -1,36 +0,0 @@
FROM ghcr.io/linuxserver/baseimage-alpine-nginx:3.14
# set version label
ARG BUILD_DATE
ARG TP_RELEASE
LABEL build_version="Version:- ${VERSION} Build-date:- ${BUILD_DATE}"
LABEL maintainer="gilbn"
RUN \
echo " ## Installing packages ## " && \
apk add --no-cache --virtual=build-dependencies \
curl && \
echo "**** install theme.park ****" && \
mkdir -p /app/themepark && \
if [ -z ${TP_RELEASE+x} ]; then \
TP_RELEASE=$(curl -sX GET "https://api.github.com/repos/gilbn/theme.park/releases/latest" \
| awk '/tag_name/{print $4;exit}' FS='[""]'); \
fi && \
curl -o \
/tmp/themepark.tar.gz -L \
"https://github.com/GilbN/theme.park/archive/refs/tags/${TP_RELEASE}.tar.gz" && \
tar xf \
/tmp/themepark.tar.gz -C \
/app/themepark/ --strip-components=1 && \
cd /app/themepark && \
echo "**** cleanup ****" && \
apk del --purge \
build-dependencies && \
rm -rf \
/root/.cache \
/tmp/* \
/app/themepark/docker-mods \
/app/themepark/resources/organizr
# copy local files
COPY root/ /

View File

@ -4,7 +4,7 @@ server {
server_name _; server_name _;
root /app/themepark; root /config/www;
index index.html index.htm index.php; index index.html index.htm index.php;
location / { location / {
@ -12,7 +12,7 @@ server {
sub_filter 'https://theme-park.dev' $scheme://TP_DOMAIN; sub_filter 'https://theme-park.dev' $scheme://TP_DOMAIN;
sub_filter 'https://develop.theme-park.dev' $scheme://TP_DOMAIN; sub_filter 'https://develop.theme-park.dev' $scheme://TP_DOMAIN;
sub_filter_once off; sub_filter_once off;
try_files $uri $uri/ /index.html /index.php?$args =404; try_files $uri $uri/ /index.html;
} }
# Don't cache # Don't cache

View File

@ -6,7 +6,10 @@ echo '------------------'
# Display variables for troubleshooting # Display variables for troubleshooting
echo -e "Variables set:\\n\ echo -e "Variables set:\\n\
'TP_DOMAIN'=${TP_DOMAIN}\\n" PUID=${PUID}\\n\
PGID=${PGID}\\n\
TZ=${TZ}\\n\
TP_DOMAIN=${TP_DOMAIN}\\n"
if [[ -z ${TP_DOMAIN} ]]; then if [[ -z ${TP_DOMAIN} ]]; then
echo 'No domain set, defaulting to $http_host' echo 'No domain set, defaulting to $http_host'
@ -17,4 +20,18 @@ DEFAULT='/config/nginx/site-confs/default'
if ! grep -q "sub_filter 'https://theme-park.dev' \$scheme://${TP_DOMAIN};" ${DEFAULT}; then if ! grep -q "sub_filter 'https://theme-park.dev' \$scheme://${TP_DOMAIN};" ${DEFAULT}; then
sed -i "s/sub_filter 'https:\/\/theme-park.dev' \$scheme:\/\/TP_DOMAIN;/sub_filter 'https:\/\/theme-park.dev' \$scheme:\/\/${TP_DOMAIN}; /g" ${DEFAULT} sed -i "s/sub_filter 'https:\/\/theme-park.dev' \$scheme:\/\/TP_DOMAIN;/sub_filter 'https:\/\/theme-park.dev' \$scheme:\/\/${TP_DOMAIN}; /g" ${DEFAULT}
sed -i "s/sub_filter 'https:\/\/develop.theme-park.dev' \$scheme:\/\/TP_DOMAIN;/sub_filter 'https:\/\/develop.theme-park.dev' \$scheme:\/\/${TP_DOMAIN}; /g" ${DEFAULT} sed -i "s/sub_filter 'https:\/\/develop.theme-park.dev' \$scheme:\/\/TP_DOMAIN;/sub_filter 'https:\/\/develop.theme-park.dev' \$scheme:\/\/${TP_DOMAIN}; /g" ${DEFAULT}
fi fi
# make our folders and links
mkdir -p \
/config/www/{css,resources}
# copy theme files
cp -R /app/themepark/css /config/www
cp -R /app/themepark/resources /config/www
cp /app/themepark/index.html /config/www
cp /app/themepark/themes.py /config/www
# permissions
chown -R abc:abc \
/config

View File

@ -0,0 +1,4 @@
#!/usr/bin/with-contenv bash
exec \
python3 /config/www/themes.py

View File

@ -1,12 +1,15 @@
from os import listdir #! /usr/bin/env python3
from os.path import isdir, isfile, join
from os import listdir, environ as env, chdir
from os.path import isdir, isfile, join, dirname, abspath
from json import dump, dumps, loads, load from json import dump, dumps, loads, load
import subprocess import subprocess
import shutil
chdir(dirname(abspath(__file__))) # Set working dir
def get_shas(output): def get_shas(output):
"""Returns a dict of CSS files and SHAs""" """Returns a dict of CSS files and SHAs"""
output_lines = output.splitlines() output_lines = output.splitlines() if output else []
sha_dict = {} sha_dict = {}
for line in output_lines: for line in output_lines:
line = line.decode('utf-8').replace("0\t", "").split(" ") line = line.decode('utf-8').replace("0\t", "").split(" ")
@ -17,8 +20,7 @@ def get_shas(output):
def create_addons_json(): def create_addons_json():
addon_shas = subprocess.check_output( addon_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/addons/*.css"]) if isdir(".git") else []
["git", "ls-files", "-s", "./css/addons/*.css"])
SHAS = get_shas(addon_shas) SHAS = get_shas(addon_shas)
ADDONS = {"addons": {}} ADDONS = {"addons": {}}
addon_root = './css/addons' addon_root = './css/addons'
@ -62,8 +64,8 @@ def create_addons_json():
def create_json(app_folders: list = None, themes: list = None, community_themes: list = None, no_sub_folders=False): def create_json(app_folders: list = None, themes: list = None, community_themes: list = None, no_sub_folders=False):
if no_sub_folders: if no_sub_folders:
THEMES_DICT = {} THEMES_DICT = {}
theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/theme-options/*.css"]) theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/theme-options/*.css"]) if isdir(".git") else []
community_theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/community-theme-options/*.css"]) community_theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/community-theme-options/*.css"]) if isdir(".git") else []
THEME_SHAS = get_shas(theme_shas) THEME_SHAS = get_shas(theme_shas)
COMMUNITY_THEME_SHAS = get_shas(community_theme_shas) COMMUNITY_THEME_SHAS = get_shas(community_theme_shas)
THEMES = { THEMES = {
@ -91,7 +93,7 @@ def create_json(app_folders: list = None, themes: list = None, community_themes:
else: else:
ADDONS = loads(create_addons_json()) ADDONS = loads(create_addons_json())
APPS = {} APPS = {}
app_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/base/*base.css"]) app_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/base/*base.css"]) if isdir(".git") else []
SHAS = get_shas(app_shas) SHAS = get_shas(app_shas)
APPS.update(dict(sorted({ APPS.update(dict(sorted({
"applications": { "applications": {
@ -114,25 +116,6 @@ def create_json(app_folders: list = None, themes: list = None, community_themes:
APPS.update(THEMES) APPS.update(THEMES)
return dumps(APPS) return dumps(APPS)
# def temporary_copy_files():
# shutil.rmtree("./CSS", ignore_errors=True)
# shutil.rmtree("./Resources", ignore_errors=True)
# src_dst = {
# "./css/base/": "./CSS/themes",
# "./css/theme-options": "./CSS/variables",
# "./css/community-theme-options": "./CSS/variables",
# "./resources/": "./Resources/",
# "./css/addons/": "./CSS/addons",
# "./css/defaults/": "./CSS/defaults",
# "./css/theme-options/organizr.css": "./CSS/variables/organizr-dark.css",
# "./css/theme-options/organizr.css": "./css/theme-options/organizr-dark.css"
# }
# for src in src_dst:
# if ".css" in src:
# shutil.copy(src,src_dst[src])
# continue
# shutil.copytree(src,src_dst[src],dirs_exist_ok=True)
def create_theme_options(): def create_theme_options():
def create_css(folder): def create_css(folder):
with open(f"{folder}/{app}/{theme.lower()}.css", "w") as create_app: with open(f"{folder}/{app}/{theme.lower()}.css", "w") as create_app:
@ -148,15 +131,19 @@ def create_theme_options():
for folder in folders: for folder in folders:
create_css(folder) create_css(folder)
env_domain = env.get('TP_DOMAIN')
if __name__ == "__main__": if __name__ == "__main__":
app_folders = [name for name in listdir('./css/base') if isdir(join('./css/base', name))] app_folders = [name for name in listdir('./css/base') if isdir(join('./css/base', name))]
themes = [name for name in listdir('./css/theme-options') if isfile(join('./css/theme-options', name))] themes = [name for name in listdir('./css/theme-options') if isfile(join('./css/theme-options', name))]
community_themes = [name for name in listdir('./css/community-theme-options') if isfile(join('./css/community-theme-options', name))] community_themes = [name for name in listdir('./css/community-theme-options') if isfile(join('./css/community-theme-options', name))]
with open("CNAME", "rt", closefd=True) as cname: develop = True if isdir(".git") and subprocess.check_output(["git", "symbolic-ref", "--short", "HEAD"]).decode('ascii').strip() == "develop" else False
CNAME = cname.readline() if env_domain:
develop = True if subprocess.check_output(["git", "symbolic-ref", "--short", "HEAD"]).decode('ascii').strip() == "develop" else False DOMAIN = env_domain
DOMAIN = CNAME if not develop else f"develop.{CNAME}" else:
with open("CNAME", "rt", closefd=True) as cname:
CNAME = cname.readline()
DOMAIN = CNAME if not develop else f"develop.{CNAME}"
apps = loads(create_json(app_folders=app_folders, themes=themes, community_themes=community_themes)) apps = loads(create_json(app_folders=app_folders, themes=themes, community_themes=community_themes))
with open("themes.json", "w") as outfile: with open("themes.json", "w") as outfile:
dump(apps, outfile, indent=2, sort_keys=True) dump(apps, outfile, indent=2, sort_keys=True)