Sign inSign up

jvitor83/compose-tag

By jvitor83

Updated 6 months ago

Maps docker-compose.yml image vars to pinned digests using docker buildx bake metadata output.

Image
0

241

jvitor83/compose-tag repository overview

compose-tag

Docker image that cross-references a docker-compose.yml with the metadata JSON from docker buildx bake --metadata-file to produce a .env file mapping each image variable to its resolved [email protected].

Usage

docker run --rm -v "$PWD":/workspace compose-tag [compose-file] [metadata-file] [output-file]
ArgumentDefaultDescription
compose-filedocker-compose.ymlCompose file with ${VAR} image refs
metadata-filemeta.jsonMetadata JSON from docker buildx bake
output-filetags.envOutput .env file
Example

Given a docker-compose.yml:

services:
  api:
    image: ${API_IMAGE:-my-registry/api:latest}
  web:
    image: ${WEB_IMAGE:-my-registry/web:latest}
  db:
    image: postgres:16

And a meta.json (from docker buildx bake --metadata-file meta.json):

{
  "api": {
    "image.name": "my-registry/api",
    "containerimage.digest": "sha256:abc123..."
  },
  "web": {
    "image.name": "my-registry/web",
    "containerimage.digest": "sha256:def456..."
  }
}

Run:

docker run --rm -v "$PWD":/workspace compose-tag docker-compose.yml meta.json tags.env

Output tags.env:

API_IMAGE=registry.example.com/api:latest@sha256:abc123...
WEB_IMAGE=registry.example.com/web:latest@sha256:def456...

The db service is ignored because its image doesn't use a ${VAR} reference.

NOTE: LATEST IS IGNORED WHEN DIGEST IS PRESENT AND THE IMAGE PULLED IS THE HASH ONE.

Tag summary

Content type

Image

Digest

sha256:6050d5de6

Size

8.2 MB

Last updated

6 months ago

docker pull jvitor83/compose-tag:1.0.0