Compare commits

..

10 Commits

Author SHA1 Message Date
bbbfdf07de some info 2023-10-08 01:31:19 +05:00
6a36e6870f added spec 2023-10-08 01:23:23 +05:00
ec4c0d09a6 add some colors 2023-10-08 00:55:19 +05:00
7c54edc17b it was a wrong thing lol 2023-10-08 00:53:58 +05:00
a29d22aff2 how to update 2023-10-08 00:53:12 +05:00
bc78d63da2 install command 2023-10-08 00:52:02 +05:00
58b4e61fd0 build and push works, somewhat 2023-10-08 00:39:43 +05:00
cd10376a3e test tagging 2023-10-08 00:00:59 +05:00
dc5833730c empty context 2023-10-06 01:43:43 +05:00
82e2cc3167 empty Dockerfile 2023-10-06 01:36:20 +05:00
3 changed files with 92 additions and 6 deletions

View File

@@ -1,7 +1,14 @@
# container-compose
An implementation of [Compose Spec](https://compose-spec.io/) with support for [Podman](https://podman.io/) and [Docker](https://www.docker.com/) backend.
This project focuses on:
neither docker-compose or podman-compose supports building multi arch images and push them to registrar. this is a bash script to attempt to fix it and add support for it.
* Multiarch container build and push to regitrar
# Selecting backend engine:
- Pass `--engine=docker` or `--engine=podman` as first argument or it will use select engine based on compose file name `docker` if `docker-compose.yaml` or `docker-compose.yml` and podman if `podman-compose.yaml` or `podman-compose.yml`.
### Spec to follow
[https://github.com/compose-spec/compose-spec/blob/master/spec.md#compose-file](https://github.com/compose-spec/compose-spec/blob/master/spec.md#compose-file)
This script checks if current dir has one of these files, in this oder
```text
@@ -14,3 +21,13 @@ podman-compose.yml
container-compose.yaml
container-compose.yml
```
# Install system-wide
**WARNING: DO NOT RUN RANDOM COMMANDS OFF THE INTERNET LIKE THIS, READ WHAT IT DOES AND RUN ONLY IF YOU CAN TRUST IT!**
*anyway..*
```bash
sudo curl -L https://git.shihaam.dev/shihaam/container-compose/raw/branch/main/container-compose -o /usr/local/bin/container-compose \
&& sudo chmod +x /usr/local/bin/container-compose
```
Run the same command again to update it.

View File

@@ -23,7 +23,7 @@ check_file() {
shift # Remove build from positional parameters
;;
push)
push=push
push=true
shift # Remove build from positional parameters
;;
pull)
@@ -131,6 +131,7 @@ build(){
platform=$(yq e ".services.$service.platform" "$file")
image=$(yq e ".services.$service.image" "$file")
build=$(yq e ".services.$service.build" "$file")
context=$(yq e ".services.$service.build.context" "$file")
dockerfile=$(yq e ".services.$service.build.dockerfile" "$file")
# Replace '/' and ':' with '-' in the platform string to make it suitable for a tag
@@ -138,11 +139,60 @@ build(){
# Append platform information to the image tag
new_image_tag="${image}-${platform_tag}"
$engine buildx build --platform $platform -t $new_image_tag -f $context/$dockerfile $context
# If dockerfile is null or empty, set it to "Dockerfile"
if [ -z "$dockerfile" ]; then
dockerfile="Dockerfile"
fi
if [ -z "$context" ]; then
context="."
fi
$engine buildx build --platform $platform -t $new_image_tag -f $context/$dockerfile $context --load
done
}
#push(){
#}
push(){
services=$(yq e '.services | keys | .[]' "$file")
for service in $services; do
platform=$(yq e ".services.$service.platform" "$file")
image=$(yq e ".services.$service.image" "$file")
build=$(yq e ".services.$service.build" "$file")
context=$(yq e ".services.$service.build.context" "$file")
dockerfile=$(yq e ".services.$service.build.dockerfile" "$file")
# Replace '/' and ':' with '-' in the platform string to make it suitable for a tag
platform_tag=$(echo "$platform" | tr '/:' '-')
# Append platform information to the image tag
new_image_tag="${image}-${platform_tag}"
# If dockerfile is null or empty, set it to "Dockerfile"
if [ -z "$dockerfile" ]; then
dockerfile="Dockerfile"
fi
if [ -z "$context" ]; then
context="."
fi
echo push both tags cmd: $engine push $new_image_tag
$engine push $new_image_tag
done
################################################################ BOTH IMAGES PUSHED
manifest_create_cmd="$engine manifest create $image"
echo $manifest_create_cmd
services=$(yq e '.services | keys | .[]' "$file")
for service in $services; do
platform=$(yq e ".services.$service.platform" "$file")
image=$(yq e ".services.$service.image" "$file")
# Replace '/' and ':' with '-' in the platform string to make it suitable for a tag
platform_tag=$(echo "$platform" | tr '/:' '-')
# Append platform information to the image tag
new_image_tag="${image}-${platform_tag}"
manifest_create_cmd+=" $new_image_tag"
done
echo Manifest Create cmd: $manifest_create_cmd
$manifest_create_cmd
#########################################
echo manifest push cmd: $engine manifest push $image
$engine manifest push $image
}
pull(){
services=$(yq e '.services | keys | .[]' "$file")
@@ -156,4 +206,7 @@ if [ "$pull" = true ]; then
pull
elif [ "$build" = true ]; then
build
elif [ "$push" = true ]; then
# echo push
push
fi

16
testtag.sh Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/bash
image="nginx:latest"
platforms=("amd64" "arm64")
engine="docker"
# Start the command string
cmd="$engine manifest create $image"
# Append each platform-specific image to the command string
for platform in "${platforms[@]}"; do
cmd+=" $image-$platform"
done
# Output the complete command string
echo "$cmd"