This repository has been archived on 2023-05-06. You can view files and clone it, but cannot push or open issues or pull requests.
helix/internal/docker/image.go

51 lines
1.2 KiB
Go
Raw Normal View History

2021-06-26 01:26:06 +01:00
package docker
import (
"fmt"
"github.com/pulumi/pulumi-docker/sdk/v3/go/docker"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// DockerImageInput is the configuration
2021-06-26 01:26:06 +01:00
// used to create the local Gitea docker
// image.
type DockerImageInput struct {
2021-06-26 01:26:06 +01:00
BuildContext pulumi.StringInput
Dockerfile pulumi.StringInput
ImageName pulumi.StringInput
ImageTag pulumi.StringInput
UniqueLabel string
}
// DockerImageOutput contains the details
// of the generated Docker image.
type DockerImageOutput struct {
ImageName pulumi.StringOutput
2021-06-26 01:26:06 +01:00
}
// CreateDockerImage creates a local Docker image.
func CreateImage(ctx *pulumi.Context, c DockerImageInput) (DockerImageOutput, error) {
var output DockerImageOutput
2021-06-26 01:26:06 +01:00
args := docker.ImageArgs{
ImageName: pulumi.Sprintf("%s:%s", c.ImageName, c.ImageTag),
2021-06-26 01:26:06 +01:00
SkipPush: pulumi.Bool(true),
Build: docker.DockerBuildArgs{
Context: c.BuildContext,
Dockerfile: c.Dockerfile,
2021-06-26 01:26:06 +01:00
},
}
i, err := docker.NewImage(ctx, fmt.Sprintf("%s_image", c.UniqueLabel), &args)
2021-06-26 01:26:06 +01:00
if err != nil {
return output, fmt.Errorf("unable to create the Docker image for %s...\n%w", c.UniqueLabel, err)
}
output = DockerImageOutput{
ImageName: i.BaseImageName,
2021-06-26 01:26:06 +01:00
}
return output, nil
2021-06-26 01:26:06 +01:00
}