Pulled build script out of Dockerfile to facilitate native builds, changed the base image from alpine-s6 to alpine and used tini as entrypoint
This commit is contained in:
@@ -1,13 +1,109 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
MK_TARGETS=${TARGETS:-"linux/amd64,linux/386,linux/arm64,linux/arm/v7,linux/arm/v6"}
|
||||
MK_VERSION=${VERSION:-2.0.32}
|
||||
MK_GO_VERSION=${GO_VERSION:-1.23.7}
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
function help_message() {
|
||||
echo "Usage: $0 [OPTIONS]"
|
||||
echo "Options:"
|
||||
echo " --targets, -t <targets> Comma-separated list of target platforms (default: current, use 'all' for all supported targets)"
|
||||
echo " --version, -v <version> Psiphon version to build (default: 2.0.32)"
|
||||
echo " --go, -g <version> Go version to use (default: 1.22.7)"
|
||||
echo " --help, -h Show this help message and exit"
|
||||
echo " --supported-targets Show supported targets and exit"
|
||||
exit ${1:-1}
|
||||
}
|
||||
|
||||
EXTRA_BUILD_ARGS=""
|
||||
VERSION=""
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--help|-h)
|
||||
help_message 0
|
||||
;;
|
||||
--targets=*)
|
||||
TARGETS="${1#*=}"
|
||||
shift
|
||||
;;
|
||||
-t | --targets)
|
||||
TARGETS="$2"
|
||||
shift 2
|
||||
;;
|
||||
--version=*)
|
||||
VERSION="${1#*=}"
|
||||
shift
|
||||
;;
|
||||
-v | --version)
|
||||
VERSION="$2"
|
||||
shift 2
|
||||
;;
|
||||
--go=*)
|
||||
GO_VERSION="${1#*=}"
|
||||
shift
|
||||
;;
|
||||
-g | --go)
|
||||
GO_VERSION="$2"
|
||||
shift 2
|
||||
;;
|
||||
--supported-targets)
|
||||
echo "Supported targets: $(get_supported_targets)"
|
||||
exit 0
|
||||
;;
|
||||
--current-target)
|
||||
echo "Current target: $(get_current_target)"
|
||||
exit 0
|
||||
;;
|
||||
-l | --load)
|
||||
if [[ -n ${EXTRA_BUILD_ARGS} && ${EXTRA_BUILD_ARGS} == *"--push"* ]]; then
|
||||
echo "Error: --load and --push cannot be used together." >&2
|
||||
exit 1
|
||||
fi
|
||||
EXTRA_BUILD_ARGS="--load"
|
||||
shift
|
||||
;;
|
||||
-p | --push)
|
||||
if [[ -n ${EXTRA_BUILD_ARGS} && ${EXTRA_BUILD_ARGS} == *"--load"* ]]; then
|
||||
echo "Error: --load and --push cannot be used together." >&2
|
||||
exit 1
|
||||
fi
|
||||
EXTRA_BUILD_ARGS="--push"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Error: Unknown option '$1'" >&2
|
||||
help_message
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
TARGETS=${TARGETS:-"current"}
|
||||
GO_VERSION=${GO_VERSION:-1.22.7}
|
||||
|
||||
MYPATH=$(dirname "$(readlink -f "$0")")
|
||||
source "${MYPATH}/latest_version.sh"
|
||||
|
||||
DOCKER_BUILD_ARGS=()
|
||||
|
||||
if [[ -n "${TARGETS}" ]]; then
|
||||
DOCKER_BUILD_ARGS+=(--build-arg TARGETS=${TARGETS})
|
||||
fi
|
||||
if [[ -z "${VERSION}" ]]; then
|
||||
VERSION=$(get_latest_version)
|
||||
fi
|
||||
if [[ -n "${VERSION}" ]]; then
|
||||
VERSION=$(normalize_version "${VERSION}")
|
||||
DOCKER_BUILD_ARGS+=(--build-arg PSIPHON_VERSION=${VERSION})
|
||||
fi
|
||||
if [[ -n "${GO_VERSION}" ]]; then
|
||||
DOCKER_BUILD_ARGS+=(--build-arg GO_VERSION=${GO_VERSION})
|
||||
fi
|
||||
|
||||
DECIPHERED_TARGETS=$(decipher_targets "${TARGETS}")
|
||||
|
||||
docker buildx build \
|
||||
--build-arg TARGETS=${MK_TARGETS} \
|
||||
--build-arg PSIPHON_VERSION=${MK_VERSION} \
|
||||
--build-arg GO_VERSION=${MK_GO_VERSION} \
|
||||
-t swarupsengupta2007/psiphon:${MK_VERSION} \
|
||||
"${DOCKER_BUILD_ARGS[@]}" \
|
||||
-t swarupsengupta2007/psiphon:"${VERSION#v}" \
|
||||
-t swarupsengupta2007/psiphon:latest \
|
||||
--platform ${MK_TARGETS} . $1
|
||||
--platform "${DECIPHERED_TARGETS}" . \
|
||||
${EXTRA_BUILD_ARGS}
|
||||
|
||||
Reference in New Issue
Block a user