From 478143dccf4d7ff29aa8494b2474b211d06836aa Mon Sep 17 00:00:00 2001 From: GilbN Date: Tue, 22 Mar 2022 10:05:36 +0100 Subject: [PATCH 1/4] docker build changes --- .github/workflows/docker-build.yml | 26 ++++++------ Dockerfile | 23 +++++++++++ docker/Dockerfile | 36 ----------------- docker/root/defaults/default | 4 +- docker/root/etc/cont-init.d/50-config | 21 +++++++++- docker/root/etc/services.d/themepark/run | 4 ++ themes.py | 51 +++++++++--------------- 7 files changed, 81 insertions(+), 84 deletions(-) create mode 100644 Dockerfile delete mode 100644 docker/Dockerfile create mode 100644 docker/root/etc/services.d/themepark/run diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index d310dfcb..df886386 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -2,7 +2,10 @@ name: docker build on: release: types: - - published + - released + push: + branches: + - develop jobs: push_to_ghcr_io: runs-on: ubuntu-latest @@ -11,7 +14,6 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 - ref: ${{ github.event.release.target_commitish }} - name: Get the version id: get_version run: echo ::set-output name=VERSION::${{ github.event.release.tag_name }} @@ -24,15 +26,15 @@ jobs: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GH_PAT }} - - name: build&push live + - name: build&push master if: ${{ github.event.release.target_commitish == 'live' }} 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 - - name: build&push dev - if: ${{ github.event.release.target_commitish == 'live_develop' }} + - name: build&push develop + if: ${{ github.ref == 'refs/heads/develop' }} 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 push_to_dockerhub: runs-on: ubuntu-latest @@ -52,14 +54,14 @@ jobs: with: username: ${{ secrets.DH_USER }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: build&push dh live + - name: build&push dh master if: ${{ github.event.release.target_commitish == 'live' }} 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 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 gilbn/theme.park - - name: build&push dh dev - if: ${{ github.event.release.target_commitish == 'live_develop' }} + - name: build&push dh develop + if: ${{ github.ref == 'refs/heads/develop' }} 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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..c68117e8 --- /dev/null +++ b/Dockerfile @@ -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/ / \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index b3c14960..00000000 --- a/docker/Dockerfile +++ /dev/null @@ -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/ / diff --git a/docker/root/defaults/default b/docker/root/defaults/default index 2dd596d4..58eddb72 100644 --- a/docker/root/defaults/default +++ b/docker/root/defaults/default @@ -4,7 +4,7 @@ server { server_name _; - root /app/themepark; + root /config/www; index index.html index.htm index.php; location / { @@ -12,7 +12,7 @@ server { sub_filter 'https://theme-park.dev' $scheme://TP_DOMAIN; sub_filter 'https://develop.theme-park.dev' $scheme://TP_DOMAIN; sub_filter_once off; - try_files $uri $uri/ /index.html /index.php?$args =404; + try_files $uri $uri/ /index.html; } # Don't cache diff --git a/docker/root/etc/cont-init.d/50-config b/docker/root/etc/cont-init.d/50-config index 6d78f576..fdd5f88a 100644 --- a/docker/root/etc/cont-init.d/50-config +++ b/docker/root/etc/cont-init.d/50-config @@ -6,7 +6,10 @@ echo '------------------' # Display variables for troubleshooting 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 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 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} -fi \ No newline at end of file +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 \ No newline at end of file diff --git a/docker/root/etc/services.d/themepark/run b/docker/root/etc/services.d/themepark/run new file mode 100644 index 00000000..3e1ae806 --- /dev/null +++ b/docker/root/etc/services.d/themepark/run @@ -0,0 +1,4 @@ +#!/usr/bin/with-contenv bash + + exec \ + python3 /config/www/themes.py \ No newline at end of file diff --git a/themes.py b/themes.py index 4b369a2e..48b50039 100644 --- a/themes.py +++ b/themes.py @@ -1,12 +1,15 @@ -from os import listdir -from os.path import isdir, isfile, join +#! /usr/bin/env python3 + +from os import listdir, environ as env, chdir +from os.path import isdir, isfile, join, dirname, abspath from json import dump, dumps, loads, load import subprocess -import shutil + +chdir(dirname(abspath(__file__))) # Set working dir def get_shas(output): """Returns a dict of CSS files and SHAs""" - output_lines = output.splitlines() + output_lines = output.splitlines() if output else [] sha_dict = {} for line in output_lines: line = line.decode('utf-8').replace("0\t", "").split(" ") @@ -17,8 +20,7 @@ def get_shas(output): def create_addons_json(): - addon_shas = subprocess.check_output( - ["git", "ls-files", "-s", "./css/addons/*.css"]) + addon_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/addons/*.css"]) if isdir(".git") else [] SHAS = get_shas(addon_shas) ADDONS = {"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): if no_sub_folders: THEMES_DICT = {} - theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/theme-options/*.css"]) - community_theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/community-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"]) if isdir(".git") else [] THEME_SHAS = get_shas(theme_shas) COMMUNITY_THEME_SHAS = get_shas(community_theme_shas) THEMES = { @@ -91,7 +93,7 @@ def create_json(app_folders: list = None, themes: list = None, community_themes: else: ADDONS = loads(create_addons_json()) 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) APPS.update(dict(sorted({ "applications": { @@ -114,25 +116,6 @@ def create_json(app_folders: list = None, themes: list = None, community_themes: APPS.update(THEMES) 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_css(folder): with open(f"{folder}/{app}/{theme.lower()}.css", "w") as create_app: @@ -148,15 +131,19 @@ def create_theme_options(): for folder in folders: create_css(folder) +env_domain = env.get('TP_DOMAIN') if __name__ == "__main__": 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))] 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: - CNAME = cname.readline() - develop = True if subprocess.check_output(["git", "symbolic-ref", "--short", "HEAD"]).decode('ascii').strip() == "develop" else False - DOMAIN = CNAME if not develop else f"develop.{CNAME}" + develop = True if isdir(".git") and subprocess.check_output(["git", "symbolic-ref", "--short", "HEAD"]).decode('ascii').strip() == "develop" else False + if env_domain: + DOMAIN = env_domain + 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)) with open("themes.json", "w") as outfile: dump(apps, outfile, indent=2, sort_keys=True) From 4a0b89e4df4e362ff6678bbaee86c6fcdb427585 Mon Sep 17 00:00:00 2001 From: GilbN Date: Tue, 22 Mar 2022 10:07:06 +0100 Subject: [PATCH 2/4] workflow fix --- .github/workflows/docker-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index df886386..57784406 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -29,12 +29,12 @@ jobs: - name: build&push master if: ${{ github.event.release.target_commitish == 'live' }} run: | - 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 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 - name: build&push develop if: ${{ github.ref == 'refs/heads/develop' }} run: | - 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 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 push_to_dockerhub: runs-on: ubuntu-latest From 20245e17f26280d2b1356aeb897f874a3b6ddee8 Mon Sep 17 00:00:00 2001 From: GilbN Date: Tue, 22 Mar 2022 10:09:42 +0100 Subject: [PATCH 3/4] fix the fix? --- .github/workflows/docker-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 57784406..24c72345 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -29,12 +29,12 @@ jobs: - name: build&push master if: ${{ github.event.release.target_commitish == 'live' }} run: | - 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 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 - name: build&push develop if: ${{ github.ref == 'refs/heads/develop' }} run: | - 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 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 push_to_dockerhub: runs-on: ubuntu-latest From 1ec977e4a57ffdec30593ecb62718fe571f51069 Mon Sep 17 00:00:00 2001 From: GilbN Date: Tue, 22 Mar 2022 10:12:37 +0100 Subject: [PATCH 4/4] dot --- .github/workflows/docker-build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 24c72345..1044842e 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -34,7 +34,7 @@ jobs: - name: build&push develop if: ${{ github.ref == 'refs/heads/develop' }} run: | - 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 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 push_to_dockerhub: runs-on: ubuntu-latest @@ -57,11 +57,11 @@ jobs: - name: build&push dh master if: ${{ github.event.release.target_commitish == 'live' }} run: | - 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 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 gilbn/theme.park - name: build&push dh develop if: ${{ github.ref == 'refs/heads/develop' }} run: | - 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 build --build-arg TP_RELEASE=${{ steps.get_version.outputs.VERSION }} --build-arg BUILD_DATE=${{ steps.date_time.outputs.NOW }} --tag gilbn/theme.park:develop . docker push --all-tags gilbn/theme.park