From bf6ece1591d217a6366664b416d8e174d00579bd Mon Sep 17 00:00:00 2001 From: KyleTryon Date: Thu, 24 Oct 2024 19:34:00 -0400 Subject: [PATCH 1/3] docs: docker compose bake --- content/guides/docker-compose.mdx | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/content/guides/docker-compose.mdx b/content/guides/docker-compose.mdx index 0f372dd..d96b660 100644 --- a/content/guides/docker-compose.mdx +++ b/content/guides/docker-compose.mdx @@ -95,3 +95,46 @@ When using `docker compose build` with Depot, there are a few things to be aware 3. It's not possible to use multiple different Depot projects for different Compose services with `docker compose build`. However, `depot configure-docker` does directly integrate with any tools that use Docker Buildx, so if you are unable to use `depot bake --load` or otherwise need full Buildx compatibility with other tools, this is a good option. + +## Building and testing `docker compose` on GitHub Actions + +As we described above, the `depot bake` command can accept a `docker-compose.yml` file and build all services in parallel. However, by default this command will not load the images back into the local Docker daemon, which is necessary for running `docker compose` commands. +In this example, we demonstrate how to use `depot bake` to build all services defined in a `docker-compose.yml` file, followed by `depot pull` to load the built images into the local Docker daemon. This makes it possible to run `docker compose` commands, such as `docker compose run tests`, as usual. Once the tests pass, you can use depot push to push the images to a registry. + +```yaml +name: Depot example compose +on: push + +permissions: + contents: read + id-token: write + packages: write + +jobs: + compose-example: + runs-on: depot-ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: depot/setup-action@v1 + + - name: Build, cache, and save all compose images to the depot ephemeral registry. + uses: depot/bake-action@v1 + id: bake + with: + files: docker-compose.yml + save: true + + - name: Pull all compose service images locally from the ephemeral registry. + uses: depot/pull-action@v1 + with: + build-id: ${{ steps.bake.outputs.build-id }} + + - name: Run compose up (images should not rebuild) + run: | + docker compose up + + - name: If successful push the srv1 compose service target image to ghcr.io from ephemeral registry + run: | + echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $ --password-stdin + depot push --target srv1 -t ghcr.io/depot/srv1:latest ${{ steps.build.outputs.build-id }} +``` From b9eb8a53f4fe7794e614ae9a092ce7631433618c Mon Sep 17 00:00:00 2001 From: KyleTryon Date: Fri, 25 Oct 2024 10:15:03 -0400 Subject: [PATCH 2/3] docs: updated example --- content/guides/docker-compose.mdx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/content/guides/docker-compose.mdx b/content/guides/docker-compose.mdx index d96b660..71648e6 100644 --- a/content/guides/docker-compose.mdx +++ b/content/guides/docker-compose.mdx @@ -98,8 +98,7 @@ However, `depot configure-docker` does directly integrate with any tools that us ## Building and testing `docker compose` on GitHub Actions -As we described above, the `depot bake` command can accept a `docker-compose.yml` file and build all services in parallel. However, by default this command will not load the images back into the local Docker daemon, which is necessary for running `docker compose` commands. -In this example, we demonstrate how to use `depot bake` to build all services defined in a `docker-compose.yml` file, followed by `depot pull` to load the built images into the local Docker daemon. This makes it possible to run `docker compose` commands, such as `docker compose run tests`, as usual. Once the tests pass, you can use depot push to push the images to a registry. +With the `depot/bake-action` action and the `--save` flag, we can build all of the services in a Compose file in parallel and save them to the Depot ephemeral registry. Then, with the `depot/pull-action`, we can pull all of the images back into the local Docker daemon for testing in subsequent jobs. ```yaml name: Depot example compose @@ -111,12 +110,13 @@ permissions: packages: write jobs: - compose-example: - runs-on: depot-ubuntu-22.04 + build-services: + runs-on: ubuntu-22.04 + outputs: + build-id: ${{ steps.bake.outputs.build-id }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: depot/setup-action@v1 - - name: Build, cache, and save all compose images to the depot ephemeral registry. uses: depot/bake-action@v1 id: bake @@ -124,15 +124,19 @@ jobs: files: docker-compose.yml save: true + test: + runs-on: depot-ubuntu-22.04 + needs: [build-services] + steps: + - uses: actions/checkout@v4 + - uses: depot/setup-action@v1 - name: Pull all compose service images locally from the ephemeral registry. uses: depot/pull-action@v1 with: - build-id: ${{ steps.bake.outputs.build-id }} - + build-id: ${{ needs.build-services.outputs.build-id }} - name: Run compose up (images should not rebuild) run: | docker compose up - - name: If successful push the srv1 compose service target image to ghcr.io from ephemeral registry run: | echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $ --password-stdin From 8af074c4aa3a17ccb6519196be6c30e8e4c279a7 Mon Sep 17 00:00:00 2001 From: "Kyle a.k.a. TechSquidTV" Date: Mon, 28 Oct 2024 08:39:18 -0400 Subject: [PATCH 3/3] Update content/guides/docker-compose.mdx Co-authored-by: Jacob Gillespie --- content/guides/docker-compose.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/guides/docker-compose.mdx b/content/guides/docker-compose.mdx index 71648e6..8fd2341 100644 --- a/content/guides/docker-compose.mdx +++ b/content/guides/docker-compose.mdx @@ -136,7 +136,7 @@ jobs: build-id: ${{ needs.build-services.outputs.build-id }} - name: Run compose up (images should not rebuild) run: | - docker compose up + docker compose up -d - name: If successful push the srv1 compose service target image to ghcr.io from ephemeral registry run: | echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $ --password-stdin