#!/usr/bin/env bash set -euo pipefail scriptDir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" envFile="$scriptDir/.env" if [[ -f "$envFile" ]]; then set -a source "$envFile" set +a else echo "Error: .env file not found at $envFile" >&2 exit 1 fi : "${GITEA_REGISTRY:?The GITEA_REGISTRY variable is not set}" : "${GITEA_USER:?The GITEA_USER variable is not set}" : "${GITEA_TOKEN:?The GITEA_TOKEN variable is not set}" : "${GITEA_OWNER:?The GITEA_OWNER variable is not set}" serviceName="${1:?Usage: $0 [base-tag]}" imageBaseTag="${2:-latest}" buildContext="$scriptDir/$serviceName" if [[ ! -d "$buildContext" ]]; then echo "Error: build context '$buildContext' not found" >&2 exit 1 fi imageFullTag="$imageBaseTag-$(date +%y.%m.%d)" imageFull="$GITEA_REGISTRY/$GITEA_OWNER/$serviceName:$imageFullTag" imageLatest="$GITEA_REGISTRY/$GITEA_OWNER/$serviceName:$imageBaseTag-latest" # --- Login --- echo "Login to $GITEA_REGISTRY" echo "$GITEA_TOKEN" | docker login "$GITEA_REGISTRY" --username "$GITEA_USER" --password-stdin # --- Build --- echo "Image build: $imageFull" docker build -t "$imageFull" -t "$imageLatest" "$buildContext" # --- Push --- echo "Image push: $imageFull" docker push "$imageFull" echo "Image push: $imageLatest" docker push "$imageLatest" echo "Complete" # bash build.sh openlitespeed 1.8.5-lsphp85-multiphp # GitLab ====================================================================== # registry="registry.wedos.org/mk250/sodew-bash" # imageName="openlitespeed" # imageBaseTag="1.8.5-lsphp85-multiphp" # imageFullTag="${imageBaseTag}-$(date +%y.%m.%d)" # imageFull="$registry/${imageName}:${imageFullTag}" # imageLatest="$registry/${imageName}:${imageBaseTag}-latest" # echo "Image build: ${imageFull}" # docker build -t "${imageFull}" -t "${imageLatest}" "$(dirname "$0")" # echo "Image push: ${imageFull}" # docker push "${imageFull}" # echo "Image push: ${imageLatest}" # docker push "${imageLatest}" # echo "Compete" # Export and deploy to k3s node # nodeHost="139.sodew.ai" # tarFile="/tmp/${imageName}-${imageFullTag}.tar.gz" # echo "Export image: ${tarFile}" # docker save "${imageFull}" | gzip > "${tarFile}" # echo "Copy to node: ${nodeHost}" # scp "${tarFile}" "root@${nodeHost}:/tmp/" # echo "Import to k3s containerd" # ssh "root@${nodeHost}" "k3s ctr images import /tmp/$(basename ${tarFile}) && rm /tmp/$(basename ${tarFile})" # rm "${tarFile}" # echo "Complete" # Download # docker save registry.wedos.org/mk250/sodew-bash/openlitespeed:1.8.5-lsphp85-multiphp-26.08.06 | gzip > ./images/ols-1.8.5-lsphp85-multiphp-26.08.06.tar.gz # docker save "$imageFull" | gzip > "./images/$imageFullTag.tar.gz" # ========================================================= ### If no Docker registry # ========================================================= ## 1. pull and save image # docker pull registry.wedos.org:443/mk250/sodew-bash/openlitespeed:1.8.5-lsphp85-multiphp-26.08.06 # docker save registry.wedos.org/mk250/sodew-bash/openlitespeed:1.8.5-lsphp85-multiphp-26.08.06 | gzip > ols-1.8.5-lsphp85-multiphp-26.08.06.tar.gz ## 2. copy to work server # scp ols-image.tar.gz root@139.sodew.ai:/tmp/ ## 3. import to containerd (k3s use containerd) # k3s ctr images import /tmp/ols-image.tar.gz # =========================================================#