From b95b44d1d9cb3e7fef3fe1623b531523f6fe46bf Mon Sep 17 00:00:00 2001 From: Leopere Date: Fri, 4 Apr 2025 20:06:57 -0400 Subject: [PATCH] feat: optimize builds with Docker Buildx and Bake --- .woodpecker.yml | 21 +++++++++++++++++++++ docker-bake.hcl | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 docker-bake.hcl diff --git a/.woodpecker.yml b/.woodpecker.yml index 498f98b..c8f3ac4 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -146,4 +146,25 @@ steps: when: branch: main event: [push, cron] + status: success + +pipeline: + build: + image: docker:24.0.7 + commands: + - apk add --no-cache git + - docker buildx create --use + - docker buildx bake --file docker-bake.hcl --set *.platform=linux/amd64 --push + when: + event: push + branch: main + + deploy: + image: docker:24.0.7 + commands: + - apk add --no-cache git + - docker stack deploy --with-registry-auth -c ./stack.staging.yml ${CI_REPO_NAME}-staging + when: + event: push + branch: main status: success \ No newline at end of file diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..8cea230 --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,35 @@ +variable "REGISTRY" { + default = "git.nixc.us/colin" +} + +variable "TAG" { + default = "latest" +} + +group "default" { + targets = ["staging", "production"] +} + +target "staging" { + context = "." + dockerfile = "Dockerfile" + tags = ["${REGISTRY}/n8n:staging"] + platforms = ["linux/amd64"] + cache-from = ["type=registry,ref=${REGISTRY}/n8n:cache"] + cache-to = ["type=registry,ref=${REGISTRY}/n8n:cache"] + args = { + NODE_ENV = "production" + } +} + +target "production" { + context = "." + dockerfile = "Dockerfile" + tags = ["${REGISTRY}/n8n:production"] + platforms = ["linux/amd64"] + cache-from = ["type=registry,ref=${REGISTRY}/n8n:cache"] + cache-to = ["type=registry,ref=${REGISTRY}/n8n:cache"] + args = { + NODE_ENV = "production" + } +} \ No newline at end of file