Skip to content

Commit

Permalink
feat(cache): add more information about using github cache image
Browse files Browse the repository at this point in the history
  • Loading branch information
joelwurtz committed Jun 10, 2024
1 parent 9565d0e commit 072837b
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,10 @@ Once you have the registry, you can push the images to the registry:
castor docker:push
```

> [!WARNING] Pushing images cache from a dev environment to a registry is not recommended, as cache is highly sensitive
> to the environment and may not be compatible with other environments. It is recommended to push the cache from the CI
> environment.

This command will generate a bake file with the images to push from the `cache_from` directive of the `docker-compose.yml` file.
If you want to add more images to push, you can add the `cache_from` directive to them.

Expand All @@ -1005,13 +1009,21 @@ services:
<summary>Read the cookbook</summary>

If you are using a GitHub action to build your images, you can use the cached images from the registry to speed up the build process.
However there are few steps to make it works due to the docker binary limitations in GitHub actions.
However there are few steps to make it works nicely due to the docker binary limitations in GitHub actions.

#### Pushing images to the registry
#### Pushing images to the registry from a GitHub action

To push images to the registry in a github action you will need to do this :

1. Ensure that the github token have the `write:packages` scope.

```yaml
permissions:
contents: read
packages: write
```


2. Install Docker buildx in the github action

```yaml
Expand All @@ -1027,9 +1039,9 @@ To push images to the registry in a github action you will need to do this :
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
```

#### Using the cached images
#### Using the cached images in GitHub action

Images built when using the Docker Buildx will have a different hash than the one built with the classic Docker build.
Images layers built when using the Docker Buildx will have a different hash than the one built with the classic Docker build.
Then you will need to use a more recent version of the Docker binary to use the cached images by either:

* Use buildx in each GitHub action workflow step
Expand All @@ -1055,6 +1067,16 @@ Then you will need to use a more recent version of the Docker binary to use the
The second option is faster (there is no need to transfer images between buildx and local docker), but it is not
officially supported by GitHub actions and may break in the future.

* Login to the registry

```yaml
- name: Log in to registry
shell: bash
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
```

By default images are private in the GitHub registry, you will need to login to the registry to pull the images.

</details>

## Credits
Expand Down

0 comments on commit 072837b

Please sign in to comment.