Skip to content

Commit

Permalink
improve cache && add GHA workflow
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 14, 2024
1 parent 2e5f36b commit daf11da
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 54 deletions.
135 changes: 83 additions & 52 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ on:
permissions:
contents: read
jobs:
ubuntu:
if: startsWith(github.repository, 'Homebrew/')
dagger-ubuntu:
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
Expand All @@ -33,53 +29,88 @@ jobs:
- 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: Build & Test
uses: dagger/dagger-for-github@v5
with:
version: "latest"
verb: call
args: test --src .

- name: Publish
uses: dagger/dagger-for-github@v5
env:
HOMEBREW_BREW_DOCKER_TOKEN: ${{ secrets.HOMEBREW_BREW_DOCKER_TOKEN }}
HOMEBREW_BREW_GITHUB_PACKAGES_TOKEN: ${{ secrets.HOMEBREW_BREW_GITHUB_PACKAGES_TOKEN }}
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


#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: 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 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 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"
#- 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"
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ ENV PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:${PATH}
XDG_CACHE_HOME=/home/linuxbrew/.cache
WORKDIR /home/linuxbrew

RUN mkdir -p \
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 \
mkdir -p \
.linuxbrew/bin \
.linuxbrew/etc \
.linuxbrew/include \
Expand All @@ -76,5 +79,4 @@ RUN mkdir -p \
&& brew cleanup \
&& { git -C .linuxbrew/Homebrew config --unset gc.auto; true; } \
&& { git -C .linuxbrew/Homebrew config --unset homebrew.devcmdrun; true; } \
&& rm -rf .cache \
&& touch .linuxbrew/.homebrewdocker

0 comments on commit daf11da

Please sign in to comment.