Skip to content
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
349 changes: 349 additions & 0 deletions .github/workflows/deploy-docker-github-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,349 @@
# #
# @type github workflow
# @author Aetherinox
# @url https://github.com/Aetherinox
#
# @usage originally, Keeweb's docker files were hosted in the main branch within the folder /package/docker/*
# with the new setup, the Keeweb docker files are stored in a separate branch from main called `docker/keeweb`.
# this workflow copies the required docker files from the new branch docker/keeweb, and brings them over to the main branch
# and places them within the original subfolder `package/docker/*`
#
# @secrets secrets.ADMINSERV_GPG_KEY_ASC gpg private key (armored) | BEGIN PGP PRIVATE KEY BLOCK
# secrets.ADMINSERV_GPG_PASSPHRASE gpg private key passphrase
#
# @triggers this workflow is automatically run every time a PUSH is made to the branch `docker/keeweb`; it will copy docker/keeweb's contents
# to the main branch's `package/docker` folder.
#
# this workflow can be manually triggered (WORKFLOW_DISPATCH). to select the destination branch, click `Run Workflow` and select `Use Workflow From`
# and select the destination branch
# #

name: "🔄 Sync › Docker › Github"
run-name: "🔄 Sync › Docker › Github"

# #
# Triggers
# #

on:

# #
# Trigger › Workflow Dispatch
#
# If any values are not provided, will use fallback env variable
# #

workflow_dispatch:
inputs:

# #
# Branch › Source
#
# Where the files to be copied are
# #

BRANCH_SRC:
description: '📂 Repo › Source'
required: true
default: 'docker/keeweb'
type: string

# #
# Folder › Destination
#
# where the files will be placed
# #

FOLDER_DEST:
description: '📂 Folder › Destination'
required: true
default: 'package/docker'
type: string

# #
# true no changes to the repo will be made
# false workflow will behave normally, and push any changes detected to the files
# #

DRY_RUN:
description: '📑 Dry Run Only'
required: true
default: false
type: boolean

# #
# Trigger › Push
# #

push:
branches:
- docker/keeweb

# #
# Environment Vars
#
# BRANCH_SRC the source branch where you want to copy files from
# BRANCH_DEST the destination branch where the files will be copied to
# FOLDER_DEST the destination folder where the files will be placed within BRANCH_DEST
# BRANCH_MAIN even though this value is set below; it is a fallback.
# when the workflow is started, it will attempt to fetch
# the real default branch name.
# #

env:
BRANCH_SRC: ${{ github.event.inputs.BRANCH_SRC || 'docker/keeweb' }}
BRANCH_DEST: ${{ github.ref_name || 'main' }}
FOLDER_DEST: ${{ github.event.inputs.FOLDER_DEST || 'package/docker' }}
BRANCH_MAIN: 'main'

BOT_NAME_1: EuropaServ
BOT_NAME_DEPENDABOT: dependabot[bot]

# #
# Jobs
#
# The way pushed docker containers on Github work, the most recent image built goes at the top.
# We will use the order below which builds the :latest image last so that it appears at the very
# top of the packages page.
# #

jobs:

# #
# Job › Create Tag
# #

job-docker-release-tags-create:
name: >-
📦 Release › Sync
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
attestations: write
id-token: write
steps:

# #
# Sync › Start
# #

- name: "✅ Start"
id: task_sync_start
run: |
echo "Starting branch sync"

# #
# Sync › Checkout
# #

- name: "☑️ Checkout"
id: task_sync_checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# #
# Sync › Install Dependencies
# #

- name: "📦 Install Dependencies"
id: task_sync_dependencies
run:
sudo apt-get install -qq dos2unix

# #
# Sync › Get Default Branch Name
#
# attempts to get the name of the default branch so that we don't have to manually changes
# #

- name: "🔍 Find Default Branch Name"
id: task_sync_branch_default_get
run:
echo "BRANCH_MAIN=${{ github.event.repository.default_branch }}" >> $GITHUB_ENV

# #
# Sync › Debug
# #

- name: '⚠️ Env Variable › Check'
id: task_sync_vars_check
run: |
if [[ "${{ env.BRANCH_SRC }}" == "${{ env.BRANCH_DEST }}" ]]; then
branch_default="${{ env.BRANCH_MAIN }}"
echo "⚠️⚠️⚠️ Source and destination branches are the same, changing destination branch to $branch_default ⚠️⚠️⚠️"
echo "BRANCH_DEST=$(echo $branch_default)" >> $GITHUB_ENV
fi

# #
# Sync › Var Check › Confirm
# #

- name: '⚠️ Env Variable › Confirm'
id: task_sync_vars_confirm
run: |
echo "BRANCH_DEST is now ${{ env.BRANCH_DEST }}"

# #
# Sync › Checkpoint › 1
# #

- name: '⚠️ Checkpoint 1'
id: task_sync_checkpoint_1
run: |
echo "github.actor.......... ${{ github.actor }}"
echo "github.ref ........... ${{ github.ref }}"
echo "github.ref_name ...... ${{ github.ref_name }}"
echo "github.event_name .... ${{ github.event_name }}"
echo "inputs.DRY_RUN ....... ${{ inputs.DRY_RUN }}"
echo "env.BRANCH_SRC........ ${{ env.BRANCH_SRC }}"
echo "env.BRANCH_DEST....... ${{ env.BRANCH_DEST || env.BRANCH_MAIN }}"
echo "env.FOLDER_DEST....... ${{ env.FOLDER_DEST }}"

echo " ⚠️⚠️⚠️⚠️ This workflow will copy files [ 📄 root Dockerfile* ] from branch 🏠 ${{ env.BRANCH_SRC }} to 🔄 ${{ env.BRANCH_DEST || env.BRANCH_MAIN }} to folder 📂 ${{ env.FOLDER_DEST }} ⚠️⚠️⚠️"
echo " › Copy files ............. 📄 root Dockerfile*"
echo " › From branch ............ 🏠 ${{ env.BRANCH_SRC }}"
echo " › To branch .............. 🔄 ${{ env.BRANCH_DEST || env.BRANCH_MAIN }}"
echo " › In folder .............. 📂 ${{ env.FOLDER_DEST }}"

# #
# Sync › Copy Dockerfiles to Main branch
#
# this action copies all the required docker files from the docker/keeweb branch, over to
# the main branch within the subfolder `package/docker/*`
#
# to discard the actions of git checkout and not commit, run:
# git checkout -
#
# if you are copying files from docker/keeweb which don't exist on the main branch, you must
# run `git add package/docker` to track the new files / folders added
#
# this step does the following:
# - deletes the package/docker/* folder contents on the destination repo
# - sets a few settings to get rid of annoying features
# - git checkout origin/main (destination branch)
# - git checkout origin/docker/keeweb (source branch) and sets working tree to /package/docker/
# - adds all changes to git which will be committed in a later step
# #

- name: '⬇️ Pull Docker Files'
id: task_sync_files_pull
run: |
rm -rf ${{ env.FOLDER_DEST }}/*
mkdir -p ${{ env.FOLDER_DEST }}
git config --global pager.diff false
git config --global advice.detachedHead false
git checkout origin/${{ env.BRANCH_DEST || env.BRANCH_MAIN }} # ${{ github.ref_name || 'main' }}
git --work-tree=${{ env.FOLDER_DEST }} checkout origin/${{ env.BRANCH_SRC }} -- root Dockerfile* # 'docker/keeweb'
git add ${{ env.FOLDER_DEST }}

# #
# Sync › Run permission management
# #

- name: '#️⃣ Manage Permissions'
id: task_sync_fix_permissions
run: |
find ${{ env.FOLDER_DEST }} -name 'run' -exec chmod 755 {} \;
WRONG_PERM=$(find ${{ env.FOLDER_DEST }} -path "./.git" -prune -o \( -name "run" -o -name "finish" -o -name "check" \) -not -perm -u=x,g=x,o=x -print)
if [ -n "${WRONG_PERM}" ]; then
for i in ${WRONG_PERM}; do
echo "::error file=${i},line=1,title=Missing Executable Bit::This file needs to be set as executable!"
done
exit 1
else
echo "**** Executable permissions are OK ****"
fi

# #
# Sync › Run dos2unix
# #

- name: '🔐 Apply dos2unix'
id: task_sync_fix_dos2unix
run: |
find ${{ env.FOLDER_DEST }} -type f | grep -Ev '.git|.github|*.jpg|*.jpeg|*.png' | xargs dos2unix --

# #
# Sync › Show Differences
#
# this is just a debugging step, it shows all the files pending commit that will be committed.
# if you are stuck in the git pager, hit "Q" to quit.
#
# to disable the pager, run the command:
# git config --global pager.diff false
# #

- name: '📑 View Differences'
id: task_sync_debug_diff
run: |
git diff --name-only HEAD

# #
# Sync › Precommit
#
# define the date/time and the commit message
# #

- name: '📦 Commit › Pre-commit'
id: task_sync_commit_pre
run: |
now=$(date -u '+%m/%d/%Y %H:%M')
commit_label="chore(auto): Docker Sync" >> $GITHUB_ENV
commit_message="\`️️$commit_label 🔄\` \`$now UTC\`" >> $GITHUB_ENV
echo "COMMIT_MESSAGE=$(echo $commit_message)" >> $GITHUB_ENV
echo "NOW=$(echo $now)" >> $GITHUB_ENV

# #
# Sync › GPG Key
#
# this step is required so that you can sign commits in the last step
# stefanzweifel/git-auto-commit-action@v5
# #

- name: '📦 Commit › GPG Key'
id: task_sync_commit_gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.ADMINSERV_GPG_KEY_ASC }}
passphrase: ${{ secrets.ADMINSERV_GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

# #
# Sync › Checkpoint › 2
# #

- name: '⚠️ Checkpoint 2'
id: task_sync_checkpoint_2
run: |
echo "github.actor.......... ${{ github.actor }}"
echo "github.ref ........... ${{ github.ref }}"
echo "github.ref_name ...... ${{ github.ref_name }}"
echo "github.event_name .... ${{ github.event_name }}"
echo "inputs.DRY_RUN ....... ${{ inputs.DRY_RUN }}"

echo " ⚠️⚠️⚠️⚠️ This workflow will copy files [ 📄 root Dockerfile* ] from branch 🏠 ${{ env.BRANCH_SRC }} to 🔄 ${{ env.BRANCH_DEST || env.BRANCH_MAIN }} to folder 📂 ${{ env.FOLDER_DEST }} ⚠️⚠️⚠️"
echo " › Copy files ............. 📄 root Dockerfile*"
echo " › From branch ............ 🏠 ${{ env.BRANCH_SRC }}"
echo " › To branch .............. 🔄 ${{ env.BRANCH_DEST || env.BRANCH_MAIN }}"
echo " › In folder .............. 📂 ${{ env.FOLDER_DEST }}"

# #
# Sync › Commit
#
# commits the pending changes to the main branch
# #

- name: '🔄 Sync › Commit'
id: task_sync_commit
uses: stefanzweifel/git-auto-commit-action@v5
if: ( github.event_name == 'workflow_dispatch' && inputs.DRY_RUN == false ) || ( github.event_name == 'push' )
with:
commit_message: ${{ env.COMMIT_MESSAGE }}
commit_author: "${{ steps.task_sync_commit_gpg.outputs.name }} <${{ steps.task_sync_commit_gpg.outputs.email }}>"
commit_user_name: ${{ steps.task_sync_commit_gpg.outputs.name }}
commit_user_email: ${{ steps.task_sync_commit_gpg.outputs.email }}
branch: ${{ env.BRANCH_DEST || env.BRANCH_MAIN }}
add_options: '-u'
Loading
Loading