Skip to content

Commit 85b1bcc

Browse files
committed
feat(pipeline): add dryccfile support
1 parent 96288fb commit 85b1bcc

2 files changed

Lines changed: 48 additions & 16 deletions

File tree

rootfs/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ FROM registry.drycc.cc/drycc/base:${CODENAME}
44
ENV DRYCC_UID=1001 \
55
DRYCC_GID=1001 \
66
DRYCC_HOME_DIR=/home/drycc \
7+
JQ_VERSION="1.7.1" \
8+
YQ_VERSION="4.43.1" \
79
PODMAN_VERSION="4.7.1" \
810
MC_VERSION="2023.09.20.15.22.31" \
911
CADDY_VERSION="2.7.1" \
@@ -16,6 +18,8 @@ RUN groupadd drycc --gid ${DRYCC_GID} \
1618
ADD . /
1719

1820
RUN install-packages procps psmisc \
21+
&& install-stack jq $JQ_VERSION \
22+
&& install-stack yq $YQ_VERSION \
1923
&& install-stack podman $PODMAN_VERSION \
2024
&& install-stack mc $MC_VERSION \
2125
&& install-stack caddy $CADDY_VERSION \

rootfs/imagebuilder/build

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,63 @@ else
9393
--tls-verify=false > /dev/null
9494
fi
9595

96-
# Get image name and image tag
97-
drycc_app=$(echo "${IMAGE_NAME}" | awk -F '/' '{print $NF}' | awk -F ':' '{print $1}')
98-
image_tag=$(echo "${IMAGE_NAME}" | awk -F ':' '{print $NF}')
99-
image_base_name=$(echo "${IMAGE_NAME}" | sed -s "s#:${image_tag}##g")
100-
image_cache_name="${image_base_name}":cache
101-
image_latest_name="${image_base_name}":latest
96+
envfile="${HOME}"/.config/build-env
97+
dryccfile="drycc.yaml"
98+
# create build-env
99+
touch "${envfile}"
100+
if [[ -f .build-env ]] ; then
101+
cat .build-env >> "${envfile}"
102+
fi
103+
if [[ -f "$dryccfile" ]]; then
104+
config=$(cat < "$dryccfile" | yq .build.config -o json)
105+
if [[ $config != null ]]; then
106+
mapfile -t items < <(echo "$config" | jq -c -r 'to_entries[] | (.key, .value)')
107+
for ((i=0; i<"${#items[@]}"; i=i+2)); do
108+
echo "${items[i]}=${items[i+1]}" >> "${envfile}"
109+
done
110+
fi
111+
fi
102112

103113
# Building
104114
if [[ "${DRYCC_STACK}" == "container" ]] ; then
105115
echo "---> Building container"
106-
podman_build="podman build . --tag ${IMAGE_NAME} --network host"
107-
podman_push="podman push ${IMAGE_NAME} --tls-verify=false"
108-
if [[ -f .build-env ]] ; then
109-
for build_arg in $( < .build-env )
116+
builds=("web" "Dockerfile")
117+
if [[ -e "$dryccfile" ]]; then
118+
docker=$(cat < "$dryccfile" | yq .build.docker -o json)
119+
if [[ $docker != null ]]; then
120+
mapfile -t builds < <(echo "$docker" | jq -c -r 'to_entries[] | (.key, .value)')
121+
fi
122+
fi
123+
for ((i=0; i<"${#builds[@]}"; i=i+2)); do
124+
procfile_type="${builds[i]}"
125+
if [[ "${procfile_type}" == "web" ]]; then
126+
image="${IMAGE_NAME}"
127+
else
128+
image="${IMAGE_NAME}"-"${procfile_type}"
129+
fi
130+
dockerfile="${builds[i+1]}"
131+
podman_build="podman build . -f ${dockerfile} --tag ${image} --network host"
132+
podman_push="podman push ${image} --tls-verify=false"
133+
for build_arg in $( < "${envfile}" )
110134
do
111135
podman_build="$podman_build --build-arg $build_arg"
112136
done
113-
fi
114-
$podman_build
115-
$podman_push
137+
$podman_build
138+
$podman_push
139+
done
116140
else
117141
echo "---> Building pack"
118142
echo "---> Using builder ${pack_builder}"
119143
# podman connection
120144
DOCKER_HOST="unix://$(podman info -f '{{.Host.RemoteSocket.Path}}')"
121145
readonly DOCKER_HOST
122146
export DOCKER_HOST
147+
# Get image name and image tag
148+
drycc_app=$(echo "${IMAGE_NAME}" | awk -F '/' '{print $NF}' | awk -F ':' '{print $1}')
149+
image_tag=$(echo "${IMAGE_NAME}" | awk -F ':' '{print $NF}')
150+
image_base_name=$(echo "${IMAGE_NAME}" | sed -s "s#:${image_tag}##g")
151+
image_cache_name="${image_base_name}":cache
152+
image_latest_name="${image_base_name}":latest
123153

124154
pack_build="pack build ${IMAGE_NAME} \
125155
--builder ${pack_builder} \
@@ -131,15 +161,13 @@ else
131161
--cache-image ${image_cache_name} \
132162
--tag ${image_latest_name} \
133163
--default-process web \
164+
--env-file ${envfile} \
134165
--network host"
135166
if [[ $log_level == "debug" ]] ; then
136167
pack_build="$pack_build --verbose"
137168
fi
138169
if [[ -f .clear-cache ]]; then
139170
pack_build="$pack_build --clear-cache"
140171
fi
141-
if [[ -f .build-env ]] ; then
142-
pack_build="$pack_build --env-file .build-env"
143-
fi
144172
$pack_build
145173
fi

0 commit comments

Comments
 (0)