-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpush.sh
More file actions
executable file
·161 lines (146 loc) · 5.25 KB
/
push.sh
File metadata and controls
executable file
·161 lines (146 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
#
# Copyright 2025 torerodev
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Manual build and push to GHCR with Docker Buildx support
#
# Source .env file if it exists to get default versions
if [ -f .env ]; then
source .env
fi
# display usage
usage() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -v, --version VERSION Container version (default: ${VERSION:-1.5.0})"
echo " -t, --torero-version VERSION Torero version (default: ${TORERO_VERSION:-1.5.0})"
echo " -p, --python-version VERSION Python version (default: ${PYTHON_VERSION:-3.13.0})"
echo " -o, --opentofu-version VERSION OpenTofu version (default: ${OPENTOFU_VERSION:-1.10.5})"
echo " -u, --username USERNAME GitHub username"
echo " -h, --help Show this help message"
}
# prompt for a value if not provided
prompt_for_value() {
local var_name="$1"
local prompt_text="$2"
local default_value="$3"
if [ -z "${!var_name}" ]; then
if [ -n "$default_value" ]; then
read -p "$prompt_text [$default_value]: " input
eval "$var_name=\"${input:-$default_value}\""
else
while [ -z "${!var_name}" ]; do
read -p "$prompt_text: " input
eval "$var_name=\"$input\""
if [ -z "${!var_name}" ]; then
echo "This value is required."
fi
done
fi
fi
}
# set hard-coded variables
REGISTRY="ghcr.io"
IMAGE_NAME="torerodev/torero-container"
BUILDER_NAME="torero-multiarch-builder"
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-v|--version)
VERSION="$2"
shift 2
;;
-t|--torero-version)
TORERO_VERSION="$2"
shift 2
;;
-p|--python-version)
PYTHON_VERSION="$2"
shift 2
;;
-o|--opentofu-version)
OPENTOFU_VERSION="$2"
shift 2
;;
-u|--username)
GITHUB_USERNAME="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1"
usage
exit 1
;;
esac
done
# prompt for missing values
prompt_for_value "VERSION" "Enter container version" "${VERSION:-1.5.0}"
prompt_for_value "TORERO_VERSION" "Enter Torero version" "${TORERO_VERSION:-1.5.0}"
prompt_for_value "PYTHON_VERSION" "Enter Python version" "${PYTHON_VERSION:-3.13.0}"
prompt_for_value "OPENTOFU_VERSION" "Enter OpenTofu version" "${OPENTOFU_VERSION:-1.10.5}"
prompt_for_value "GITHUB_USERNAME" "Enter GitHub username"
# login to GHCR
echo "Logging into GHCR..."
echo "You'll need a GitHub Personal Access Token with 'write:packages' permission"
docker login ghcr.io -u "$GITHUB_USERNAME"
# Setup Docker Buildx for multi-arch builds
echo "Setting up Docker Buildx for multi-arch builds..."
# Check if our builder already exists
if docker buildx ls | grep -q "^${BUILDER_NAME}"; then
echo "Using existing buildx builder: ${BUILDER_NAME}"
docker buildx use ${BUILDER_NAME}
else
echo "Creating new buildx builder: ${BUILDER_NAME}"
docker buildx create --name ${BUILDER_NAME} --driver docker-container --use
fi
# Bootstrap the builder (start it up)
echo "Bootstrapping buildx builder..."
docker buildx inspect ${BUILDER_NAME} --bootstrap
# Show the current builder
echo "Current builder configuration:"
docker buildx ls
# build for current platform (for local testing)
echo "Building image for local testing..."
docker build -t ${REGISTRY}/${IMAGE_NAME}:${VERSION} \
--build-arg TORERO_VERSION=${TORERO_VERSION} \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--build-arg OPENTOFU_VERSION=${OPENTOFU_VERSION} \
-f Containerfile .
# test the image locally
echo "Testing image locally..."
docker run --rm ${REGISTRY}/${IMAGE_NAME}:${VERSION} torero version
docker run --rm ${REGISTRY}/${IMAGE_NAME}:${VERSION} python3 --version
docker run --rm ${REGISTRY}/${IMAGE_NAME}:${VERSION} tofu version
# build and push multi-arch using buildx
echo "Building and pushing multi-arch image..."
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag ${REGISTRY}/${IMAGE_NAME}:${VERSION} \
--tag ${REGISTRY}/${IMAGE_NAME}:latest \
--build-arg TORERO_VERSION=${TORERO_VERSION} \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--build-arg OPENTOFU_VERSION=${OPENTOFU_VERSION} \
--push \
-f Containerfile .
echo "Done! Pushed multi-arch image to:"
echo " ${REGISTRY}/${IMAGE_NAME}:${VERSION} (linux/amd64, linux/arm64)"
echo " ${REGISTRY}/${IMAGE_NAME}:latest (linux/amd64, linux/arm64)"
echo ""
echo "To switch back to the default Docker driver, run:"
echo " docker buildx use default"