diff --git a/.env b/.env index 05231807a..eb6fc7859 100644 --- a/.env +++ b/.env @@ -23,4 +23,4 @@ COMPOSE_PROJECT_NAME='metacall' # Configure default variables METACALL_PATH=/usr/local/metacall METACALL_BUILD_TYPE=relwithdebinfo -METACALL_BASE_IMAGE=debian:trixie-slim # debian:bookworm-slim # ubuntu:jammy # ubuntu:mantic # alpine:3.17 +METACALL_BASE_IMAGE=debian:bookworm-slim # debian:bookworm-slim # ubuntu:jammy # ubuntu:mantic # alpine:3.17 diff --git a/.github/workflows/multiarch-dockerhub.yml b/.github/workflows/multiarch-dockerhub.yml new file mode 100644 index 000000000..8b6cb3c78 --- /dev/null +++ b/.github/workflows/multiarch-dockerhub.yml @@ -0,0 +1,97 @@ +name: Build and Push Docker Image + +on: + pull_request: + workflow_dispatch: + push: + branches: + - master + tags: + - 'v*.*' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + IMAGE_NAME: index.docker.io/metacall/core + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm/v6 + - linux/arm/v7 + - linux/arm64 + + steps: + - name: Checkout the code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGE_NAME }} + + - name: Prepare + run: | + echo "METACALL_PLATFORM=${{ matrix.platform //\//- }}" >> $GITHUB_ENV + + - name: Build and Push Multi-Architecture Images + run: | + bash ./docker-compose.sh build-multiarch + + # - name: Export digest + # id: export_digest + # run: | + # digest=$(docker inspect --format='{{index .RepoDigests 0}}' ${{ env.IMAGE_NAME }}:latest) + # echo "DIGEST=${digest#*:}" >> $GITHUB_ENV + + - name: Logout from DockerHub + run: docker logout + + # create-manifest: + # needs: build + # steps: + # - name: Checkout the code + # uses: actions/checkout@v3 + + # - name: Set up Docker Buildx + # uses: docker/setup-buildx-action@v3 + + # - name: Login to DockerHub + # uses: docker/login-action@v2 + # with: + # username: ${{ secrets.DOCKER_HUB_USERNAME }} + # password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + # - name: Create manifest list and push + # run: | + # docker buildx imagetools create --tag ${{ env.IMAGE_NAME }}:latest \ + # --tag ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }} \ + # ${{ env.IMAGE_NAME }}@sha256:${{ env.DIGEST }} + + - name: Inspect image + run: docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:latest + + - name: Logout from DockerHub + run: docker logout diff --git a/docker-compose-multiarch.yml b/docker-compose-multiarch.yml new file mode 100644 index 000000000..f4b92968c --- /dev/null +++ b/docker-compose-multiarch.yml @@ -0,0 +1,34 @@ +version: "3.7" + +services: + deps: + platform: + - ${METACALL_PLATFORM} + build: + context: . + dockerfile: tools/deps/Dockerfile + image: metacall/core:deps + + dev: + platform: + - ${METACALL_PLATFORM} + build: + context: . + dockerfile: tools/dev/Dockerfile + image: metacall/core:dev + + runtime: + platform: + - ${METACALL_PLATFORM} + build: + context: . + dockerfile: tools/runtime/Dockerfile + image: metacall/core:runtime + + cli: + platform: + - ${METACALL_PLATFORM} + build: + context: . + dockerfile: tools/cli/Dockerfile + image: metacall/core:cli diff --git a/docker-compose.sh b/docker-compose.sh index fb13d8b55..a03fb31c9 100755 --- a/docker-compose.sh +++ b/docker-compose.sh @@ -68,6 +68,38 @@ sub_build() { $DOCKER_COMPOSE -f docker-compose.yml build --force-rm cli } +sub_build_multiarch() { + + # Enable BuildKit and set Docker CLI build for Compose + export DOCKER_BUILDKIT=1 + export COMPOSE_DOCKER_CLI_BUILD=1 + + if [ -z "$IMAGE_NAME" ]; then + echo "Error: IMAGE_NAME variable not defined" + exit 1 + fi + + # Create a new builder instance and use it + docker buildx create --name mybuilder --use + + # Inspect the builder instance to ensure it's correctly set up + docker buildx inspect --bootstrap + + # Build multi-architecture images using Buildx + ln -sf tools/deps/.dockerignore .dockerignore + $DOCKER_COMPOSE -f docker-compose.yml -f docker-compose-multiarch.yml build --force-rm deps + + ln -sf tools/dev/.dockerignore .dockerignore + $DOCKER_COMPOSE -f docker-compose.yml -f docker-compose-multiarch.yml build --force-rm dev + + ln -sf tools/runtime/.dockerignore .dockerignore + $DOCKER_COMPOSE -f docker-compose.yml -f docker-compose-multiarch.yml build --force-rm runtime + + ln -sf tools/cli/.dockerignore .dockerignore + $DOCKER_COMPOSE -f docker-compose.yml -f docker-compose-multiarch.yml build --force-rm cli + +} + # Build MetaCall Docker Compose without cache (link manually dockerignore files) sub_rebuild() { ln -sf tools/deps/.dockerignore .dockerignore @@ -311,6 +343,9 @@ case "$1" in build) sub_build ;; + build-multiarch) + sub_build_multiarch + ;; rebuild) sub_rebuild ;;