Skip to content

Commit

Permalink
feat: add support to build image from docker file
Browse files Browse the repository at this point in the history
Signed-off-by: dineshkumar-j-genea <[email protected]>
  • Loading branch information
dineshkumar-j-genea committed Oct 4, 2024
1 parent b343fee commit 1d1ff51
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ test:acceptancetests:
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- mv ./kubectl /usr/bin/kubectl
- wget https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_linux_amd64 -O yq
- chmod +x yq
- mv yq /usr/local/bin

script:
- ./acceptance-tests/run.sh
Expand Down
36 changes: 34 additions & 2 deletions gen/app-gen
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,35 @@ prepare_images() {
local url_current
local url_new
local output_dir
local services

# Extract services from the Docker Compose file
services=$(docker compose --project-directory "$manifests_dir" config --services)
for service in $services; do
# Convert Docker Compose config to JSON
config_json=$(docker compose --project-directory "$manifests_dir" config | yq eval -o=json)
# Check if the service has a build context
build_context=$(echo "$config_json" | jq -r ".services.\"$service\".build.context // empty")
if [ -n "$build_context" ]; then
echo "Building Images from Project"
# Build the image locally using Docker Compose
docker compose --project-directory "$manifests_dir" build "$service"
image_name=$(echo "$config_json" | jq -r ".services.\"$service\".image")
images+=("$image_name")
images+=("$image_name")
else
echo "Pulling Images from Directory"
# Get the image name from the Docker Compose file
image_name=$(echo "$config_json" | jq -r ".services.\"$service\".image")
images+=("$image_name")
images+=("$image_name")
# Pull the image from the registry
pull_image "$image_name"
fi
# images_shas+=($(get_image_sha "$image_name"))
done

for ((i = 0; i < ${#images[@]}; i++)); do
pull_image "${images[${i}]}"
images_shas+=($(get_image_sha "${images[${i}]}"))
done
declare -p images_shas
Expand Down Expand Up @@ -565,7 +591,13 @@ generate_metadata() {

prepare_images "${temp_dir}/images"
( cd "${temp_dir}" && tar czvf images.tar.gz images )
cp -a "${manifests_dir}" "${temp_dir}/manifests"
mkdir "${temp_dir}/manifests"
for file in "${manifests_dir}/docker-compose.{yaml,yml}"; do
if [ -e "$file" ]; then
cp -a "$file" "${temp_dir}/manifests/docker-compose.yaml"
break # Exit the loop after copying the first found file
fi
done
( cd "${temp_dir}" && tar czvf "manifests.tar.gz" manifests )
generate_metadata "${temp_dir}/metadata.json"

Expand Down

0 comments on commit 1d1ff51

Please sign in to comment.