Skip to content

Commit 91007b3

Browse files
committed
feat(build): add drycc v2 support
1 parent 2681e29 commit 91007b3

2 files changed

Lines changed: 68 additions & 52 deletions

File tree

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,27 @@ For more information about the Drycc Workflow, please visit the main project pag
77

88
We welcome your input! If you have feedback, please [submit an issue][issues]. If you'd like to participate in development, please read the "Development" section below and [submit a pull request][prs].
99

10-
# About
10+
# Build config
1111

1212
The V3 version of imagebuilder unifies the building model, uses the latest CNCF [buildpack](https://github.com/buildpacks) building program, and also supports the dockerfile format.
1313

1414
You can use `DRYCC_STACK` specifies the construction mode. Currently, you can choose two construction formats: `container` and `buildpack`.
1515

16-
If you want to disable caching during building, you only need to generate a `.clear-cache` file in the root directory of the project.
16+
## Build arg config
1717

18-
# Development
18+
In Container Build, build arguments (ARG) a means to pass information into the build process. You can use them to parameterize the build, allowing for more flexible and configurable builds.
19+
20+
It can be configured through `.build-arg`, argument=value to supply to the builder, this configuration file is universal in both container and buildpack scenarios.
21+
22+
## Container config
23+
24+
Normally, in container mode, as long as there is a Dockerfile in the root directory, it is sufficient, but we can use [drycc config path](https://www.drycc.cc/docs/applications/using-dryccpath/) to configure the build process more finely.
25+
26+
## Buildpack config
27+
28+
Add an empty `.clean_cache` file, clear image's associated cache before building.
29+
30+
## Development
1931

2032
The Drycc project welcomes contributions from all developers. The high level process for development matches many other open source projects. See below for an outline.
2133

rootfs/imagebuilder/build

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,38 @@ function waiting_process {
3636
done
3737
}
3838

39-
function write_build_env {
40-
local envfile dryccfile command config items i arraytype
41-
envfile=$1
39+
function podman_publish {
40+
local image dryccfile
41+
image=$1
4242
dryccfile=$2
43-
arraytype=$(cat < "$dryccfile" | yq ".build" -o json | jq '.config|type=="array"')
4443

45-
if [[ -z "$3" || "$arraytype" == "true" ]]; then
46-
command=".build.config"
47-
else
48-
command=".build.config.${3}"
44+
podman_build="podman build . -f ${dockerfile} --tag ${image} --network host"
45+
podman_push="podman push ${image} --tls-verify=false"
46+
# append build arg
47+
for build_arg in $( < "${envfile}" )
48+
do
49+
podman_build="$podman_build --build-arg $build_arg"
50+
done
51+
# append ptype build arg
52+
if [[ -n "$3" ]]; then
53+
for build_arg in $( < "${3}" )
54+
do
55+
podman_build="$podman_build --build-arg $build_arg"
56+
done
4957
fi
58+
# build and push
59+
$podman_build
60+
$podman_push
61+
}
62+
63+
function write_build_env {
64+
local envfile dryccfile config items i
65+
envfile=$1
66+
dryccfile=$2
5067
if [[ -f "$dryccfile" ]]; then
51-
config=$(cat < "$dryccfile" | yq "$command" -o json)
68+
config=$(cat < "$dryccfile" | yq ".build.arg" -o json)
5269
if [[ $config != null ]]; then
53-
mapfile -t items < <(echo "$config" | jq -c -r '.[] | (.name, .value)')
70+
mapfile -t items < <(echo "$config" | jq -c -r 'to_entries[] | (.key, .value)')
5471
for ((i=0; i<"${#items[@]}"; i=i+2)); do
5572
echo "${items[i]}=${items[i+1]}" >> "${envfile}"
5673
done
@@ -118,50 +135,38 @@ else
118135
--tls-verify=false > /dev/null
119136
fi
120137

121-
envfile="${HOME}"/.config/build-env
122-
dryccfile="drycc.yaml"
123-
# create build-env
138+
# create global build-arg
139+
envfile="${HOME}"/.config/build-arg
124140
echo "" > "${envfile}"
125-
if [[ -f .build-env ]] ; then
126-
cat .build-env >> "${envfile}"
141+
if [[ -f .build-arg ]] ; then
142+
cat .build-arg >> "${envfile}"
127143
fi
128144

129145
# Building
130146
if [[ "${DRYCC_STACK}" == "container" ]] ; then
131-
echo "---> Building container"
132-
builds=("web" "Dockerfile")
133-
if [[ -e "$dryccfile" ]]; then
134-
docker=$(cat < "$dryccfile" | yq .build.docker -o json)
135-
if [[ $docker != null ]]; then
136-
mapfile -t builds < <(echo "$docker" | jq -c -r 'to_entries[] | (.key, .value)')
137-
else
138-
write_build_env "$envfile" "$dryccfile"
139-
fi
140-
fi
141-
for ((i=0; i<"${#builds[@]}"; i=i+2)); do
142-
procfile_type="${builds[i]}"
143-
if [[ "${procfile_type}" == "web" ]]; then
144-
image="${IMAGE_NAME}"
145-
else
146-
image="${IMAGE_NAME}"-"${procfile_type}"
147-
fi
148-
dockerfile="${builds[i+1]}"
149-
podman_build="podman build . -f ${dockerfile} --tag ${image} --network host"
150-
podman_push="podman push ${image} --tls-verify=false"
151-
for build_arg in $( < "${envfile}" )
152-
do
153-
podman_build="$podman_build --build-arg $build_arg"
154-
done
155-
typed_envfile="${HOME}/.config/build-env-${procfile_type}"
156-
echo "" > "$typed_envfile"
157-
write_build_env "$typed_envfile" "$dryccfile" "$procfile_type"
158-
for build_arg in $( < "${typed_envfile}" )
159-
do
160-
podman_build="$podman_build --build-arg $build_arg"
147+
if [[ -d ".drycc" ]]; then
148+
for dryccfile in $(find .drycc | grep -E '.(yml|yaml)$'); do
149+
ptype=$(cat < "$dryccfile" | yq .ptype -o auto)
150+
build=$(cat < "$dryccfile" | yq .build -o json)
151+
if [[ "$build" != "null" ]]; then
152+
dockerfile=$(echo "$build" | jq -r '.docker // "Dockerfile"')
153+
if [[ "${ptype}" == "web" ]]; then
154+
image="${IMAGE_NAME}"
155+
else
156+
image="${IMAGE_NAME}"-"${ptype}"
157+
fi
158+
# create ptype build-arg
159+
ptype_envfile="${HOME}/.config/build-arg-${ptype}"
160+
echo "" > "$ptype_envfile"
161+
write_build_env "$ptype_envfile" "$dryccfile"
162+
podman_publish "${image}" "${dockerfile}" "${ptype_envfile}"
163+
fi
161164
done
162-
$podman_build
163-
$podman_push
164-
done
165+
fi
166+
# build default image
167+
if [[ -f "Dockerfile" ]] && [[ $(podman images -q "${IMAGE_NAME}") == "" ]]; then
168+
podman_publish "${IMAGE_NAME}" "Dockerfile"
169+
fi
165170
else
166171
echo "---> Building pack"
167172
echo "---> Using builder ${pack_builder}"
@@ -175,7 +180,6 @@ else
175180
image_base_name=$(echo "${IMAGE_NAME}" | sed -s "s#:${image_tag}##g")
176181
image_cache_name="${image_base_name}":cache
177182
image_latest_name="${image_base_name}":latest
178-
write_build_env "$envfile" "$dryccfile"
179183
pack_build="pack build ${IMAGE_NAME} \
180184
--builder ${pack_builder} \
181185
--lifecycle-image ${pack_builder} \

0 commit comments

Comments
 (0)