Skip to content

Commit

Permalink
feat: add docker-bake file with image definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp committed Apr 1, 2024
1 parent 8ce29bf commit 80ef659
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 27 deletions.
40 changes: 13 additions & 27 deletions .github/workflows/build-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,13 @@ jobs:
uses: actions/checkout@v4

- name: 🤖 Generate dist files
run: make generate
run: ansible-playbook src/playbook.yml -l ${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}

- name: 🐳 Extract docker meta data
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_NAMESPACE }}
${{ env.GHCR_NAMESPACE }}
tags: |
type=raw,event=branch,value=latest
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
flavor: |
latest=false
prefix=${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}-
- name: Upload meta bake definition
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.php_version }}-${{ matrix.php_type }}-${{ matrix.os_name }}-${{ matrix.builder.arch }}-meta
path: ${{ steps.meta.outputs.bake-file }}
if-no-files-found: error
retention-days: 1
- name: 💻 Set up Docker for MacOS
if: ${{ matrix.builder.os == 'macos-latest' }}
uses: docker-practice/actions-setup-docker@master

- name: 🛠️ Setup docker BuildX
- name: 🛠️ Setup docker QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
Expand All @@ -74,7 +54,7 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Login to GHCR
- name: 🔑 Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
Expand All @@ -86,13 +66,19 @@ jobs:
id: bake
uses: docker/bake-action@v3
with:
targets: php-81-${{ matrix.php_type }}-${{ matrix.os_name }}
files: |
${{ steps.meta.outputs.bake-file }}
./docker-bake.hcl
set: |
*.platform=linux/${{ matrix.builder.arch }}"
*.tags=${{ steps.meta.outputs.tags }}
*.platform=linux/${{ matrix.builder.arch }}
*.output=type=image,"name=${{ env.DOCKERHUB_SLUG }},${{ env.GHCR_SLUG }}",push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
- name: 🔍 Display tags built
run: |
docker image ls --filter="reference=${{ env.DOCKER_NAMESPACE }}" --format "{{.CreatedAt}}\t{{.Size}}\t{{.Repository}}:{{.Tag}}"
- name: Export digest
run: |
mkdir -p /tmp/digests
Expand Down
130 changes: 130 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
variable "NAMESPACE" {default = "wayofdev/php-base"}
variable "RELEASE_VERSION" {default = "2.9.0"}
variable "IS_RELEASE" {default = "1"}

target "default" {
args = {
RELEASE_VERSION = "${RELEASE_VERSION}"
}
# platforms = [BAKE_LOCAL_PLATFORM]
pull = true
output = ["type=docker"]
}

function "tag" {
params = [PHP_VERSION, PHP_VARIANT, PHP_OS]
result = [
equal("1",IS_RELEASE) ? "${NAMESPACE}:${PHP_VERSION}-${PHP_VARIANT}-${PHP_OS}-${RELEASE_VERSION}" : "",
"${NAMESPACE}:${PHP_VERSION}-${PHP_VARIANT}-${PHP_OS}-latest",
]
}

###########################
## PHP 8.1
###########################
target "php-81-cli-alpine" {
inherits = ["default"]
context = "dist/base/8.1-cli-alpine"
dockerfile = "./Dockerfile"
tags = tag("8.1", "cli", "alpine")
}

target "php-81-fpm-alpine" {
inherits = ["default"]
context = "dist/base/8.1-fpm-alpine"
dockerfile = "./Dockerfile"
tags = tag("8.1", "fpm", "alpine")
}

target "php-81-supervisord-alpine" {
inherits = ["default"]
context = "dist/base/8.1-supervisord-alpine"
dockerfile = "./Dockerfile"
tags = tag("8.1", "supervisord", "alpine")
}

###########################
## PHP 8.2
###########################
target "php-82-cli-alpine" {
inherits = ["default"]
context = "dist/base/8.2-cli-alpine"
dockerfile = "./Dockerfile"
tags = tag("8.2", "cli", "alpine")
}

target "php-82-fpm-alpine" {
inherits = ["default"]
context = "dist/base/8.2-fpm-alpine"
dockerfile = "./Dockerfile"
tags = tag("8.2", "fpm", "alpine")
}

target "php-82-supervisord-alpine" {
inherits = ["default"]
context = "dist/base/8.2-supervisord-alpine"
dockerfile = "./Dockerfile"
tags = tag("8.2", "supervisord", "alpine")
}

###########################
## PHP 8.3
###########################
target "php-83-cli-alpine" {
inherits = ["default"]
context = "dist/base/8.3-cli-alpine"
dockerfile = "./Dockerfile"
tags = tag("8.3", "cli", "alpine")
}

target "php-83-fpm-alpine" {
inherits = ["default"]
context = "dist/base/8.3-fpm-alpine"
dockerfile = "./Dockerfile"
tags = tag("8.3", "fpm", "alpine")
}

target "php-83-supervisord-alpine" {
inherits = ["default"]
context = "dist/base/8.3-supervisord-alpine"
dockerfile = "./Dockerfile"
tags = tag("8.3", "supervisord", "alpine")
}

group "all" {
targets = [
# "php-81-cli-alpine",
# "php-81-fpm-alpine",
# "php-81-supervisord-alpine",
# "php-82-cli-alpine",
# "php-82-fpm-alpine",
# "php-82-supervisord-alpine",
# "php-83-cli-alpine",
# "php-83-fpm-alpine",
"php-83-supervisord-alpine",
]
}

group "php-81" {
targets = [
"php-81-cli-alpine",
"php-81-fpm-alpine",
"php-81-supervisord-alpine",
]
}

group "php-82" {
targets = [
"php-82-cli-alpine",
"php-82-fpm-alpine",
"php-82-supervisord-alpine",
]
}

group "php-83" {
targets = [
"php-83-cli-alpine",
"php-83-fpm-alpine",
"php-83-supervisord-alpine",
]
}

0 comments on commit 80ef659

Please sign in to comment.