Skip to content

Commit

Permalink
Multiarch build
Browse files Browse the repository at this point in the history
  • Loading branch information
philipreinken committed Apr 13, 2024
1 parent 1f479ec commit c829568
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
verb: call
module: '.'
args: 'build-containers-for-current-versions --flavours="apache" --php-versions="8.1,8.2,8.3" sync'
args: 'build-containers-for-current-versions --flavours="apache" --php-versions="8.2" --arches="linux/amd64,linux/arm64" sync'

build-and-push-auto:
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
Expand All @@ -50,4 +50,5 @@ jobs:
with-containers-for-current-versions \
--flavours="apache" \
--php-versions="8.2" \
--arches="linux/amd64,linux/arm64" \
publish-containers
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

services:
wavelog:
image: philipreinken/wavelog:1.3.1
image: philipreinken/wavelog:1.4
ports:
- '8080:8080'
volumes:
Expand Down
62 changes: 44 additions & 18 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ func (m *WavelogDocker) BuildContainer(
// +default="8.2"
phpVersion,
// The version of wavelog to use.
wavelogVersion string,
wavelogVersion,
// The target architecture.
// +default="linux/amd64"
arch string,
) *Container {
if phpVersion == "" {
phpVersion = "8.2"
Expand All @@ -121,7 +124,13 @@ func (m *WavelogDocker) BuildContainer(
flavour = "apache"
}

c, err := base(ctx, nil, phpVersion, flavour)
if arch == "" {
arch = "linux/amd64"
}

container := dag.Container(ContainerOpts{Platform: Platform(arch)})

c, err := base(ctx, container, phpVersion, flavour)
if err != nil {
fmt.Println(fmt.Sprintf("[WARN] %v", err))
}
Expand All @@ -146,9 +155,12 @@ func (m *WavelogDocker) WithContainer(
// +default="8.2"
phpVersion,
// The version of wavelog to use.
wavelogVersion string,
wavelogVersion,
// The target architecture.
// +default="linux/amd64"
arch string,
) *WavelogDocker {
m.Containers = append(m.Containers, m.BuildContainer(ctx, flavour, phpVersion, wavelogVersion))
m.Containers = append(m.Containers, m.BuildContainer(ctx, flavour, phpVersion, wavelogVersion, arch))

return m
}
Expand All @@ -161,7 +173,9 @@ func (m *WavelogDocker) BuildContainers(
// The PHP versions to use.
phpVersions,
// The versions of wavelog to use.
wavelogVersions []string,
wavelogVersions,
// The target architectures.
arches []string,
) ([]*Container, error) {
var containers []*Container

Expand All @@ -171,7 +185,9 @@ func (m *WavelogDocker) BuildContainers(
for _, flavour := range flavours {
for _, phpVersion := range phpVersions {
for _, wavelogVersion := range wavelogVersions {
eg.Go(m.syncBuilder(gctx, &containers, flavour, phpVersion, wavelogVersion))
for _, arch := range arches {
eg.Go(m.syncBuilder(gctx, &containers, flavour, phpVersion, wavelogVersion, arch))
}
}
}
}
Expand All @@ -191,9 +207,11 @@ func (m *WavelogDocker) WithContainers(
// The PHP versions to use.
phpVersions,
// The versions of wavelog to use.
wavelogVersions []string,
wavelogVersions,
// The target architectures.
arches []string,
) (*WavelogDocker, error) {
c, err := m.BuildContainers(ctx, flavours, phpVersions, wavelogVersions)
c, err := m.BuildContainers(ctx, flavours, phpVersions, wavelogVersions, arches)
if err != nil {
return m, err
}
Expand All @@ -209,14 +227,16 @@ func (m *WavelogDocker) BuildContainersForCurrentVersions(
// The PHP image flavours to use.
flavours,
// The PHP versions to use.
phpVersions []string,
phpVersions,
// The target architectures.
arches []string,
) ([]*Container, error) {
wavelogVersions, err := m.GetTagsForLatestTwoMinorVersions(ctx)
if err != nil {
return nil, err
}

return m.BuildContainers(ctx, flavours, phpVersions, wavelogVersions)
return m.BuildContainers(ctx, flavours, phpVersions, wavelogVersions, arches)
}

// WithContainersForCurrentVersions builds containers, automatically selecting the current versions of wavelog and attaches them to the module instance.
Expand All @@ -225,9 +245,11 @@ func (m *WavelogDocker) WithContainersForCurrentVersions(
// The PHP image flavours to use.
flavours,
// The PHP versions to use.
phpVersions []string,
phpVersions,
// The target architectures.
arches []string,
) (*WavelogDocker, error) {
c, err := m.BuildContainersForCurrentVersions(ctx, flavours, phpVersions)
c, err := m.BuildContainersForCurrentVersions(ctx, flavours, phpVersions, arches)
if err != nil {
return m, err
}
Expand All @@ -243,14 +265,16 @@ func (m *WavelogDocker) BuildContainersForAllVersions(
// The PHP image flavours to use.
flavours,
// The PHP versions to use.
phpVersions []string,
phpVersions,
// The target architectures.
arches []string,
) ([]*Container, error) {
wavelogVersions, err := m.ListTags(ctx, wavelogRepoUrl)
if err != nil {
return nil, err
}

return m.BuildContainers(ctx, flavours, phpVersions, wavelogVersions)
return m.BuildContainers(ctx, flavours, phpVersions, wavelogVersions, arches)
}

// WithContainersForAllVersions builds containers for all combinations of the given flavours and PHP versions and all versions of wavelog and attaches them to the module instance.
Expand All @@ -259,9 +283,11 @@ func (m *WavelogDocker) WithContainersForAllVersions(
// The PHP image flavours to use.
flavours,
// The PHP versions to use.
phpVersions []string,
phpVersions,
// The target architectures.
arches []string,
) (*WavelogDocker, error) {
c, err := m.BuildContainersForAllVersions(ctx, flavours, phpVersions)
c, err := m.BuildContainersForAllVersions(ctx, flavours, phpVersions, arches)
if err != nil {
return m, err
}
Expand Down Expand Up @@ -312,9 +338,9 @@ func (m *WavelogDocker) PublishContainers(ctx context.Context) error {
return nil
}

func (m *WavelogDocker) syncBuilder(ctx context.Context, containers *[]*Container, flavour, phpVersion, wavelogVersion string) func() error {
func (m *WavelogDocker) syncBuilder(ctx context.Context, containers *[]*Container, flavour, phpVersion, wavelogVersion, arch string) func() error {
return func() error {
container, err := m.BuildContainer(ctx, flavour, phpVersion, wavelogVersion).Sync(ctx)
container, err := m.BuildContainer(ctx, flavour, phpVersion, wavelogVersion, arch).Sync(ctx)

if err == nil {
// TODO: Use channels here
Expand Down

0 comments on commit c829568

Please sign in to comment.