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 <[email protected]>
  • Loading branch information
marcosnils committed Jun 18, 2024
1 parent 35f46e4 commit 0b767ee
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 92 deletions.
81 changes: 12 additions & 69 deletions .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,8 @@ jobs:
with:
version: "latest"
verb: call
args: test --src .
args: test-all --src . --commit-sha ${{ github.sha }} --brew-version "$(git describe --tags --dirty --abbrev=7)"
engine-stop: false

- name: Publish
uses: dagger/dagger-for-github@v5
Expand All @@ -44,73 +47,13 @@ jobs:
with:
version: "latest"
verb: call
args: publish-all --src . --hub-username matipan --hub-token HOMEBREW_BREW_DOCKER_TOKEN --gh-username franela --gh-token HOMEBREW_BREW_GITHUB_PACKAGES_TOKEN --commit-sha ${{ github.sha }}
args: |
publish-all --src .
--hub-username brewtestbot \
--hub-token HOMEBREW_BREW_DOCKER_TOKEN \
--gh-username BrewTestBot \
--gh-token HOMEBREW_BREW_GITHUB_PACKAGES_TOKEN \
--commit-sha ${{ github.sha }} \
--brew-version "${GITHUB_REF:10}"
#ubuntu:
#if: startsWith(github.repository, 'Homebrew/')
#runs-on: ubuntu-22.04
#strategy:
#fail-fast: false
#matrix:
#version: ["18.04", "20.04", "22.04", "24.04"]
#steps:
#- name: Checkout
#uses: actions/checkout@v4
#with:
#fetch-depth: 0
#persist-credentials: false

#- name: Fetch origin/master from Git
#run: git fetch origin master

#- name: Build Docker image
#run: |
#brew_version="$(git describe --tags --dirty --abbrev=7)"
#echo "Building for Homebrew ${brew_version}"
#docker build -t brew \
#--build-arg=version=${{matrix.version}} \
#--label org.opencontainers.image.created="$(date --rfc-3339=seconds --utc)" \
#--label org.opencontainers.image.url="https://brew.sh" \
#--label org.opencontainers.image.documentation="https://docs.brew.sh" \
#--label org.opencontainers.image.source="https://github.com/${GITHUB_REPOSITORY}" \
#--label org.opencontainers.image.version="${brew_version}" \
#--label org.opencontainers.image.revision="${GITHUB_SHA}" \
#--label org.opencontainers.image.vendor="${GITHUB_REPOSITORY_OWNER}" \
#--label org.opencontainers.image.licenses="BSD-2-Clause" \
#.

#- name: Run brew test-bot --only-setup
#run: docker run --rm brew brew test-bot --only-setup

#- name: Deploy the tagged Docker image to GitHub Packages
#if: startsWith(github.ref, 'refs/tags/')
#run: |
#brew_version="${GITHUB_REF:10}"
#echo "brew_version=${brew_version}" >> "${GITHUB_ENV}"
#echo ${{secrets.HOMEBREW_BREW_GITHUB_PACKAGES_TOKEN}} | docker login ghcr.io -u BrewTestBot --password-stdin
#docker tag brew "ghcr.io/homebrew/ubuntu${{matrix.version}}:${brew_version}"
#docker push "ghcr.io/homebrew/ubuntu${{matrix.version}}:${brew_version}"
#docker tag brew "ghcr.io/homebrew/ubuntu${{matrix.version}}:latest"
#docker push "ghcr.io/homebrew/ubuntu${{matrix.version}}:latest"

#- name: Deploy the tagged Docker image to Docker Hub
#if: startsWith(github.ref, 'refs/tags/')
#run: |
#echo ${{secrets.HOMEBREW_BREW_DOCKER_TOKEN}} | docker login -u brewtestbot --password-stdin
#docker tag brew "homebrew/ubuntu${{matrix.version}}:${brew_version}"
#docker push "homebrew/ubuntu${{matrix.version}}:${brew_version}"
#docker tag brew "homebrew/ubuntu${{matrix.version}}:latest"
#docker push "homebrew/ubuntu${{matrix.version}}:latest"

#- name: Deploy the homebrew/brew Docker image to GitHub Packages and Docker Hub
#if: startsWith(github.ref, 'refs/tags/') && matrix.version == '22.04'
#run: |
#docker tag brew "ghcr.io/homebrew/brew:${brew_version}"
#docker push "ghcr.io/homebrew/brew:${brew_version}"
#docker tag brew "ghcr.io/homebrew/brew:latest"
#docker push "ghcr.io/homebrew/brew:latest"
#docker tag brew "homebrew/brew:${brew_version}"
#docker push "homebrew/brew:${brew_version}"
#docker tag brew "homebrew/brew:latest"
#docker push "homebrew/brew:latest"
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
75 changes: 57 additions & 18 deletions dagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ 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{}

// BaseContainer returns the container from homebrew's Dockerfile.
func (m *Brew) BaseContainer(src *Directory, version, commitSha, githubRepo, repoOwner, baseImageVersion string) *Container {
func (m *Brew) BaseContainer(src *Directory, version, commitSha, githubRepo, repoOwner, baseImageVersion string, brewVersion string) *Container {
return src.DockerBuild(DirectoryDockerBuildOpts{
BuildArgs: []BuildArg{
{Name: "version", Value: baseImageVersion},
Expand All @@ -22,52 +23,90 @@ func (m *Brew) BaseContainer(src *Directory, version, commitSha, githubRepo, rep
WithLabel("org.opencontainers.image.licenses", "BSD-2-Clause").
WithLabel("org.opencontainers.image.documentation", "https://docs.brew.sh").
// TODO: you have got to fix this
WithLabel("org.opencontainers.image.created", time.Now().UTC().Format(time.RFC3339)).
WithLabel("org.opencontainers.image.created", time.Now().UTC().Format("2006-01-02 15:04:05-07:00")).
WithLabel("org.opencontainers.image.source", "https://github.com/"+githubRepo).
WithLabel("org.opencontainers.image.version", version).
WithLabel("org.opencontainers.image.version", brewVersion).
WithLabel("org.opencontainers.image.revision", commitSha).
WithLabel("org.opencontainers.image.vendor", repoOwner)
}

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 {
// 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, brewVersion string) error {
if err := m.Publish(ctx, src, "docker.io", hubUsername, hubToken, commitSHA, brewVersion); err != nil {
return err
}
return m.Publish(ctx, src, "ghcr.io", ghUsername, ghToken, commitSHA)
return m.Publish(ctx, src, "ghcr.io", ghUsername, ghToken, commitSHA, brewVersion)
}

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

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=""
commitSHA string,
// +default=""
brewVersion string,
) error {
_, err := m.BaseContainer(src, version, commitSHA, "franela/brew", "franela", version, brewVersion).
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=""
commitSHA string,
// +default=""
brewVersion 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, brewVersion).
WithExec([]string{"brew", "test-bot", "--only-setup"}).Sync(ctx)
return err
}
})
}

return nil
return eg.Wait()
}

0 comments on commit 0b767ee

Please sign in to comment.