Skip to content

Modular logistics and supply chain operating system (LSOS)

Release packages with docker bake

Eugene Dementyevb399d0092cdd
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 73d185c1..d5691dc0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -7,24 +7,52 @@ on:
- 'v*'
pull_request:
branches: [ main ]
+env:
+ REGISTRY: ghcr.io/fleetbase
jobs:
build:
name: Build and Start Docker Services
runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ packages: write
steps:
- name: Checkout Code
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
with:
submodules: recursive
- - name: Install Docker Compose
- run: |
- sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- sudo chmod +x /usr/local/bin/docker-compose
- docker-compose --version
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v2
- - name: Build and Start Docker Services
- run: |
- docker-compose up -d --build
+ - name: Log in to the Container registry
+ uses: docker/login-action@v2
+ with:
+ registry: ${{ env.REGISTRY }}
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Extract metadata (tags, labels) for Docker
+ id: meta
+ uses: docker/metadata-action@v4
+ with:
+ # this will be replaced by docker buildx bake with an empty line
+ # to get just tags without the image name
+ images: |
+ willbereplaced
+ tags: |
+ type=semver,pattern={{version}}
+ type=semver,pattern={{major}}.{{minor}}
+
+ - name: Build
+ env:
+ # get tags from the json object and pass as a string-encoded list
+ tags: "${{ toJSON(fromJSON(steps.meta.outputs.json).tags) }}"
+ uses: docker/bake-action@v2
+ with:
+ push: true
+ files: |
+ ./docker-bake.hcl
+ ${{ steps.meta.outputs.bake-file }}
diff --git a/docker-bake.hcl b/docker-bake.hcl
new file mode 100644
index 00000000..43dee2dc
--- /dev/null
+++ b/docker-bake.hcl
@@ -0,0 +1,41 @@
+// docker-bake.hcl
+variable "REGISTRY" { default = "" }
+variable "tags" { default = "[]" }
+target "docker-metadata-action" {}
+
+group "default" {
+ targets = ["app"]
+}
+
+target "app" {
+ name = "app-${tgt}"
+
+ // here we inherit from docker-metadata-action to get
+ // labels for the image
+ // Labels are used to connect the built packages to the repository.
+ inherits = ["docker-metadata-action"]
+
+ // use matrix strategy to build several targets at once
+ matrix = {
+ tgt = ["app", "scheduler", "jobs", "events"]
+ }
+ context = "./"
+ // set the target from matrix
+ target = tgt
+ dockerfile = "docker/Dockerfile"
+ platforms = [
+ "linux/amd64",
+ ]
+
+ tags = notequal("", REGISTRY) ? formatlist(
+ "${REGISTRY}/fleetbase-${tgt}:%s",
+ // some magic happens here:
+ // We replace "willbereplaced:" with "" to get rid of the fake image
+ // then we decode the json object passed as a string into a list of tags
+ // then we concat that with "latest"
+ // So in the end we'll get something like ["latest". "1.0". "1.0.0"]
+ // Then formatlist will prepend the registry and image name to each of
+ // the tags
+ concat(["latest"], jsondecode(replace(tags, "willbereplaced:", "")))
+ ) : []
+}
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 8fc854ea..b1c7e2c2 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -96,7 +96,7 @@ CMD ["/startup.sh"]
# Events stage
FROM base as events
ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
-CMD ["php", "artisan", "queue:work", "events"]2
+CMD ["php", "artisan", "queue:work", "events"]
# Jobs stage
FROM base as jobs