Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use single docker image #132

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 3 additions & 45 deletions .github/workflows/release-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ permissions:
packages: write

jobs:
ghx:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -26,47 +26,5 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish artifact-service
run: ./hack/mage tools:ghx:publish ${{ github.ref_name }}

artifact-service:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish artifact-service
run: ./hack/mage services:artifact:publish ${{ github.ref_name }}

artifactcache-service:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish artifact-service
run: ./hack/mage services:artifactcache:publish ${{ github.ref_name }}
- name: Publish docker image
run: ./hack/mage docker:publish v0.0.0-dev
50 changes: 4 additions & 46 deletions .github/workflows/release-tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ permissions:
packages: write

jobs:
gale:
binary:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -27,7 +27,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

ghx:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -45,47 +45,5 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish artifact-service
run: ./hack/mage tools:ghx:publish ${{ github.ref_name }}

artifact-service:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish artifact-service
run: ./hack/mage services:artifact:publish ${{ github.ref_name }}

artifactcache-service:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish artifact-service
run: ./hack/mage services:artifactcache:publish ${{ github.ref_name }}
- name: Publish docker image
run: ./hack/mage docker:publish ${{ github.ref_name }}
10 changes: 5 additions & 5 deletions internal/mage/dev/tools.go → internal/mage/dev/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import (

"github.com/magefile/mage/mg"

"github.com/aweris/gale/internal/mage/tools"
"github.com/aweris/gale/internal/mage/docker"
"github.com/aweris/gale/internal/version"
)

type Tools mg.Namespace
type Docker mg.Namespace

// Publish publishes dev version of the tools to the local registry.
func (_ Tools) Publish(ctx context.Context) error {
// Publish publishes dev version of the docker image to the local registry.
func (_ Docker) Publish(ctx context.Context) error {
registry := os.Getenv("_GALE_DOCKER_REGISTRY")
if registry == "" {
return fmt.Errorf("no registry set, please run `mage dev:engine:start` first,than run `eval $(mage dev:engine:env)`")
}

v := version.GetVersion()

return tools.Ghx{}.Publish(ctx, v.GitVersion)
return docker.Publish(ctx, v.GitVersion)
}
36 changes: 0 additions & 36 deletions internal/mage/dev/services.go

This file was deleted.

68 changes: 68 additions & 0 deletions internal/mage/docker/docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package docker

import (
"context"
"fmt"
"os"
"runtime"
"strings"

"dagger.io/dagger"
)

// Publish publishes the docker image for the given version.
func Publish(ctx context.Context, version string) error {
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
if err != nil {
return err
}
defer client.Close()

// ensure that the version is prefixed with a "v"
version = strings.TrimPrefix(version, "v")
version = fmt.Sprintf("v%s", version)

image := fmt.Sprintf("ghcr.io/aweris/gale:%s", version)

// If the registry is set, we'll use that instead of the default one. This is useful for testing and development.
if registry := os.Getenv("_GALE_DOCKER_REGISTRY"); registry != "" {
image = fmt.Sprintf("%s/aweris/gale:%s", registry, version)
}

var ldflags []string

ldflags = append(ldflags, "-s", "-w")
ldflags = append(ldflags, "-X github.com/aweris/gale/internal/version.gitVersion="+version)

// builds

gale := build(client, "./cmd/gale", "/src/out/gale")
ghx := build(client, "./cmd/ghx", "/src/out/ghx")
artifact := build(client, "./services/artifact", "/src/out/artifact-service")
artifactCache := build(client, "./services/artifactcache", "/src/out/artifactcache-service")

// container
_, err = client.Container().
From("alpine:latest").
WithExec([]string{"apk", "add", "--no-cache", "git", "docker", "github-cli"}).
WithFile("/usr/local/bin/gale", gale).
WithFile("/usr/local/bin/ghx", ghx).
WithFile("/usr/local/bin/artifact-service", artifact).
WithFile("/usr/local/bin/artifactcache-service", artifactCache).
WithEntrypoint([]string{"/usr/local/bin/gale"}).
Publish(ctx, image)

return err
}

func build(client *dagger.Client, path, out string) *dagger.File {
exec := []string{"go", "build", "-o", out, path}

return client.Container().
From("golang:"+strings.TrimPrefix(runtime.Version(), "go")).
WithMountedDirectory("/src", client.Host().Directory(".")).
WithWorkdir("/src").
WithEnvVariable("CGO_ENABLED", "0").
WithExec(exec).
File(out)
}
9 changes: 3 additions & 6 deletions internal/mage/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
package main

import (
//mage:import docker
_ "github.com/aweris/gale/internal/mage/docker"

//mage:import dev
_ "github.com/aweris/gale/internal/mage/dev"

//mage:import tools
_ "github.com/aweris/gale/internal/mage/tools"

//mage:import services
_ "github.com/aweris/gale/internal/mage/services"
)
63 changes: 0 additions & 63 deletions internal/mage/services/artifact.go

This file was deleted.

Loading
Loading