-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): build and publish operator and lam image with dagger (#1206)
- Loading branch information
Showing
14 changed files
with
496 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"dagger/embedded-cluster/internal/dagger" | ||
) | ||
|
||
type chainguard struct{} | ||
|
||
func (m *chainguard) melangeBuildGo( | ||
src *dagger.Directory, | ||
melangeFile *dagger.File, | ||
// +default="amd64,arm64" | ||
arch string, | ||
// +default="latest" | ||
imageTag string, | ||
) *dagger.Container { | ||
|
||
keygen := m.melangeKeygen(imageTag) | ||
|
||
c := dag.Container(). | ||
From(fmt.Sprintf("cgr.dev/chainguard/melange:%s", imageTag)). | ||
WithDirectory("/workspace", src). | ||
WithFile("/workspace/melange.yaml", melangeFile). | ||
WithFile("/workspace/melange.rsa", keygen.File("/workspace/melange.rsa")). | ||
WithMountedCache("/go/pkg/mod", dag.CacheVolume("go-mod")). | ||
WithWorkdir("/workspace"). | ||
WithExec( | ||
[]string{ | ||
"melange", "build", "melange.yaml", | ||
"--signing-key", "melange.rsa", | ||
"--cache-dir", "/go/pkg/mod", | ||
"--arch", arch, | ||
"--out-dir", "build/packages/", | ||
}, | ||
dagger.ContainerWithExecOpts{ | ||
ExperimentalPrivilegedNesting: true, | ||
InsecureRootCapabilities: true, | ||
}, | ||
) | ||
|
||
// for output | ||
c = c.WithFile("/workspace/build/melange.rsa.pub", keygen.File("/workspace/melange.rsa.pub")) | ||
|
||
return c | ||
} | ||
|
||
func (m *chainguard) melangeKeygen( | ||
// +default="latest" | ||
imageTag string, | ||
) *dagger.Container { | ||
keygen := dag.Container(). | ||
From(fmt.Sprintf("cgr.dev/chainguard/melange:%s", imageTag)). | ||
WithWorkdir("/workspace"). | ||
WithExec([]string{"melange", "keygen"}) | ||
|
||
return keygen | ||
} | ||
|
||
func (m *chainguard) apkoBuild( | ||
src *dagger.Directory, | ||
apkoFile *dagger.File, | ||
image string, | ||
// +default="amd64,arm64" | ||
arch string, | ||
// +default="latest" | ||
imageTag string, | ||
) *dagger.Container { | ||
|
||
c := dag.Container(). | ||
From(fmt.Sprintf("cgr.dev/chainguard/apko:%s", imageTag)). | ||
WithDirectory("/workspace", src). | ||
WithFile("/workspace/apko.yaml", apkoFile). | ||
WithWorkdir("/workspace"). | ||
WithExec( | ||
[]string{ | ||
"apko", "build", "apko.yaml", image, "apko.tar", | ||
"--cache-dir", "/go/pkg/mod", | ||
"--arch", arch, | ||
}, | ||
) | ||
|
||
return c | ||
} | ||
|
||
func (m *chainguard) apkoPublish( | ||
src *dagger.Directory, | ||
apkoFile *dagger.File, | ||
image string, | ||
// +default="amd64,arm64" | ||
arch string, | ||
// +default="latest" | ||
imageTag string, | ||
) *dagger.Container { | ||
|
||
c := dag.Container(). | ||
From(fmt.Sprintf("cgr.dev/chainguard/apko:%s", imageTag)). | ||
WithDirectory("/workspace", src). | ||
WithFile("/workspace/apko.yaml", apkoFile). | ||
WithWorkdir("/workspace"). | ||
WithExec( | ||
[]string{ | ||
"apko", "publish", "apko.yaml", image, | ||
"--cache-dir", "/go/pkg/mod", | ||
"--arch", arch, | ||
}, | ||
) | ||
|
||
return c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"dagger/embedded-cluster/internal/dagger" | ||
) | ||
|
||
// Builds the local artifact mirror image with APKO. | ||
func (m *EmbeddedCluster) BuildLocalArtifactMirrorImage( | ||
// Source directory to use for the build. | ||
// +defaultPath="/" | ||
src *dagger.Directory, | ||
// Repository to use for the image. | ||
// +default="replicated/embedded-cluster-local-artifact-mirror" | ||
repo string, | ||
// Version to use for the package. | ||
ecVersion string, | ||
// Architectures to build for. | ||
// +default="amd64,arm64" | ||
arch string, | ||
) *dagger.File { | ||
|
||
tag := strings.Replace(ecVersion, "+", "-", -1) | ||
image := fmt.Sprintf("%s:%s", repo, tag) | ||
|
||
apkoFile := m.apkoTemplateLocalArtifactMirror(src, ecVersion) | ||
|
||
pkgBuild := m.BuildLocalArtifactMirrorPackage(src, ecVersion, arch) | ||
|
||
dir := dag.Directory(). | ||
WithFile("melange.rsa.pub", pkgBuild.File("melange.rsa.pub")). | ||
WithDirectory("packages", pkgBuild.Directory("packages")) | ||
|
||
build := m.apkoBuild( | ||
dir, | ||
apkoFile, | ||
image, | ||
arch, | ||
APKOImageVersion, | ||
) | ||
|
||
return build.File("apko.tar") | ||
} | ||
|
||
// Builds and publishes the local artifact mirror image with APKO. | ||
func (m *EmbeddedCluster) PublishLocalArtifactMirrorImage( | ||
ctx context.Context, | ||
// Source directory to use for the build. | ||
// +defaultPath="/" | ||
src *dagger.Directory, | ||
// Repository to use for the image. | ||
// +default="replicated/embedded-cluster-local-artifact-mirror" | ||
repo string, | ||
// Version to use for the package. | ||
ecVersion string, | ||
// Architectures to build for. | ||
// +default="amd64,arm64" | ||
arch string, | ||
) (string, error) { | ||
|
||
tag := strings.Replace(ecVersion, "+", "-", -1) | ||
image := fmt.Sprintf("%s:%s", repo, tag) | ||
|
||
apkoFile := m.apkoTemplateLocalArtifactMirror(src, ecVersion) | ||
|
||
pkgBuild := m.BuildLocalArtifactMirrorPackage(src, ecVersion, arch) | ||
|
||
dir := dag.Directory(). | ||
WithFile("melange.rsa.pub", pkgBuild.File("melange.rsa.pub")). | ||
WithDirectory("packages", pkgBuild.Directory("packages")) | ||
|
||
publish := m.apkoPublish( | ||
dir, | ||
apkoFile, | ||
image, | ||
arch, | ||
APKOImageVersion, | ||
) | ||
|
||
return publish.Stdout(ctx) | ||
} | ||
|
||
// Builds the local artifact mirror package with Melange. | ||
func (m *EmbeddedCluster) BuildLocalArtifactMirrorPackage( | ||
// Source directory to use for the build. | ||
// +defaultPath="/" | ||
src *dagger.Directory, | ||
// Version to use for the package. | ||
ecVersion string, | ||
// Architectures to build for. | ||
// +default="amd64,arm64" | ||
arch string, | ||
) *dagger.Directory { | ||
|
||
melangeFile := m.melangeTemplateLocalArtifactMirror(src, ecVersion) | ||
|
||
dir := dag.Directory(). | ||
WithDirectory("local-artifact-mirror", src.Directory("local-artifact-mirror")). | ||
WithDirectory("cmd", src.Directory("cmd")) | ||
|
||
build := m.melangeBuildGo( | ||
directoryWithCommonGoFiles(dir, src), | ||
melangeFile, | ||
arch, | ||
MelangeImageVersion, | ||
) | ||
|
||
return build.Directory("build") | ||
} | ||
|
||
func (m *EmbeddedCluster) apkoTemplateLocalArtifactMirror( | ||
src *dagger.Directory, | ||
ecVersion string, | ||
) *dagger.File { | ||
return m.renderTemplate( | ||
src.Directory("local-artifact-mirror/deploy"), | ||
map[string]string{ | ||
"PACKAGE_VERSION": ecVersion, | ||
}, | ||
"apko.tmpl.yaml", | ||
"apko.yaml", | ||
) | ||
} | ||
|
||
func (m *EmbeddedCluster) melangeTemplateLocalArtifactMirror( | ||
src *dagger.Directory, | ||
ecVersion string, | ||
) *dagger.File { | ||
return m.renderTemplate( | ||
src.Directory("local-artifact-mirror/deploy"), | ||
map[string]string{ | ||
"PACKAGE_VERSION": ecVersion, | ||
}, | ||
"melange.tmpl.yaml", | ||
"melange.yaml", | ||
) | ||
} |
Oops, something went wrong.