Skip to content

Commit

Permalink
fix publish registry username
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>
  • Loading branch information
marcosnils committed Jun 18, 2024
1 parent 35f46e4 commit 92b2101
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ on:
paths:
- .github/workflows/docker.yml
- Dockerfile
- dagger/**
push:
paths:
- .github/workflows/docker.yml
- Dockerfile
- dagger/**
branches-ignore:
- master
release:
Expand All @@ -34,7 +36,7 @@ jobs:
with:
version: "latest"
verb: call
args: test --src .
args: test-all --src .

- name: Publish
uses: dagger/dagger-for-github@v5
Expand Down
17 changes: 12 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/* \
&& sed -i -E 's/^(USERGROUPS_ENAB\s+)yes$/\1no/' /etc/login.defs \
&& localedef -i en_US -f UTF-8 en_US.UTF-8 \
&& useradd --create-home --shell /bin/bash --user-group linuxbrew \
&& useradd -u 1001 --create-home --shell /bin/bash --user-group linuxbrew \
&& echo 'linuxbrew ALL=(ALL) NOPASSWD:ALL' >>/etc/sudoers \
&& su - linuxbrew -c 'mkdir ~/.linuxbrew'

Expand All @@ -58,13 +58,20 @@ ENV PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:${PATH}
XDG_CACHE_HOME=/home/linuxbrew/.cache
WORKDIR /home/linuxbrew

RUN --mount=type=cache,target=Homebrew/Library/Homebrew/vendor/portable-ruby,uid=1000 \
--mount=type=cache,target=Homebrew/Library/Taps,uid=1000 \
--mount=type=cache,target=.cache,uid=1000 \

RUN --mount=type=cache,target=/tmp/homebrew-core,uid=1001,sharing=locked \
# Clone the homebre-core repo into /tmp/homebrew-core or pull latest changes if it exists
git clone https://github.com/homebrew/homebrew-core /tmp/homebrew-core || { cd /tmp/homebrew-core && git pull; } \
&& mkdir -p /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core \
&& cp -r /tmp/homebrew-core /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/


RUN --mount=type=cache,target=/home/linuxbrew/.cache,uid=1001 \
--mount=type=cache,target=/home/linuxbrew/.bundle,uid=1001 \
mkdir -p \
.linuxbrew/bin \
.linuxbrew/etc \
.linuxbrew/include \
.linuxbrew/etc \
.linuxbrew/lib \
.linuxbrew/opt \
.linuxbrew/sbin \
Expand Down
55 changes: 45 additions & 10 deletions dagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"
"fmt"
"time"

"golang.org/x/sync/errgroup"
)

// var versions = []string{"20.04", "18.04", "16.04"}
var versions = []string{"20.04"}
var versions = []string{"24.04", "22.04", "20.04", "18.04"}

type Brew struct{}

Expand All @@ -29,45 +30,79 @@ func (m *Brew) BaseContainer(src *Directory, version, commitSha, githubRepo, rep
WithLabel("org.opencontainers.image.vendor", repoOwner)
}

// publishes to both docker.io and ghcr registries
func (m *Brew) PublishAll(ctx context.Context, src *Directory, hubUsername string, hubToken *Secret, ghUsername string, ghToken *Secret, commitSHA string) error {
if err := m.Publish(ctx, src, "docker.io", hubUsername, hubToken, commitSHA); err != nil {
return err
}
return m.Publish(ctx, src, "ghcr.io", ghUsername, ghToken, commitSHA)
}

// publishes image to specified registry
func (m *Brew) Publish(ctx context.Context, src *Directory, registry, username string, token *Secret, commitSHA string) error {
for _, version := range versions {
c := m.BaseContainer(src, version, commitSHA, "franela/brew", "franela", version)

addr, err := c.
WithRegistryAuth(registry, username, token).
Publish(ctx, registry+"/franela/brew-ubuntu:"+version)
Publish(ctx, registry+"/"+username+"/brew-ubuntu:"+version)
if err != nil {
return err
}
fmt.Println("published at", addr)

addr, err = c.
Publish(ctx, registry+"/franela/brew-ubuntu:latest")
Publish(ctx, registry+"/"+username+"/brew-ubuntu:latest")
if err != nil {
return err
}

if version == "22.04" {
addr, err = c.
Publish(ctx, registry+"/"+username+"/brew:latest")
if err != nil {
return err
}
}

fmt.Println("published at", addr)
}

return nil
}

func (m *Brew) Test(ctx context.Context, src *Directory) error {
// runs brew test-bot against latest ubuntu image
func (m *Brew) Test(ctx context.Context,
src *Directory,
// +default="24.04"
version string,
// +default="foo"
commitSHA string,
) error {
_, err := m.BaseContainer(src, version, commitSHA, "franela/brew", "franela", version).
WithExec([]string{"brew", "test-bot", "--only-setup"}).Sync(ctx)
if err != nil {
return err
}

return nil
}

// runs brew test-bot against all versions
func (m *Brew) TestAll(ctx context.Context,
src *Directory,
// +default="foo"
commitSHA string,
) error {
eg := errgroup.Group{}

for _, version := range versions {
_, err := m.BaseContainer(src, version, "foo", "franela/brew", "franela", version).
WithExec([]string{"brew", "test-bot", "--only-setup"}).Sync(ctx)
if err != nil {
eg.Go(func() error {
_, err := m.BaseContainer(src, version, commitSHA, "franela/brew", "franela", version).
WithExec([]string{"brew", "test-bot", "--only-setup"}).Sync(ctx)
return err
}
})
}

return nil
return eg.Wait()
}

0 comments on commit 92b2101

Please sign in to comment.