Skip to content

Commit

Permalink
Improve resliency of action (#19)
Browse files Browse the repository at this point in the history
Given all the recent trouble with Homebrew's conflicts and the QEMU bottle, I'm trying to improve on this regard by doing the following:

Download Colima and Lima binaries directly from their Github releases. For now, always download the latest version. Later I might add inputs to pick the version. They don't need to be cached anymore.

By default, use brew only to install Docker client and Docker Compose.

A check for QEMU's brew bottle 8.1.0 has been added. This version is broken and needs to be reinstalled by the action for things to work.

Added an input that can be used to force a QEMU upgrade.
  • Loading branch information
douglascamata authored Sep 4, 2023
1 parent 01f6996 commit 50a8f08
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
on:
push:
branches:
- "main"
pull_request:

jobs:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning].

## [Unreleased]

### Changed

- Improve reliability of action ([#19](https://github.com/douglascamata/setup-docker-macos-action/pull/19))
- Colima and Lima binaries are now downloaded straight from their Github Release pages
- By default, use `brew` only to install the Docker client and Docker Compose.
- QEMU is now installed (using `brew`) only if it's not already present.
- QEMU is upgraded (using `brew`) only if the input `upgrade-qemu` is set to `"true"`.

## [v1-alpha.9] - 2023-08-21

### Fixed
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ This action installs Docker on a macOS runner through [Colima], [Lima-VM], and [
I intend this action to be kept as simple as possible:

- No other OS will be supported.
- No other installation method for Colima will be supported (means you will always get what Homebrew gives you).
- Binaries will be downloaded directly from the source when possible.

## Features

- Safety check to ensure the action is running in macOS.
- Caches big Homebrew packages to save some CI minutes.
- As simple and lightweight (downloads binaries directly when possible).

## Inputs

## `inputs.upgrade-qemu` (defaults to `"false"`)

The action, by default, will not try to upgrade QEMU if it's already installed.
The reason is that installing QEMU takes a considerable amount of time.

If this is set to `"true"`, the action will attempt an upgrade of QEMU to the
latest version available in Homebrew.

## Outputs

Expand Down
74 changes: 35 additions & 39 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: "Setup Docker on macOS"
description: "Setup Docker on macOS using Colima, Lima-VM, and Homebrew."
inputs:
upgrade-qemu:
description: "Upgrade QEMU to the latest version. Add a lot of time to the job."
required: false
default: "false"
outputs:
colima-version:
value: ${{ steps.colima-version.outputs.version }}
Expand All @@ -22,58 +27,49 @@ runs:
- name: Update Homebrew
run: |
brew update --preinstall
brew_repository="$(brew --repository)"
mkdir -p .github
cd .github
cat "$(brew edit --print-path --formula colima)" > brew-colima
cat "$(brew edit --print-path --formula lima)" > brew-lima
cat "$(brew edit --print-path --formula docker )" > brew-docker
cat "$(brew edit --print-path --formula docker-compose)" > brew-docker-compose
shell: bash
- name: Pre-cache
run: echo "BREW_CELLAR=$(brew --cellar)" >> $GITHUB_ENV
shell: bash
- name: Configure Homebrew cache
id: homebrew-cache
uses: actions/[email protected]
with:
path: |
${{ env.BREW_CELLAR }}/colima
${{ env.BREW_CELLAR }}/lima
${{ env.BREW_CELLAR }}/docker
${{ env.BREW_CELLAR }}/docker-compose
key: brew-${{ hashFiles('.github/brew-*') }}
restore-keys: brew-${{ hashFiles('.github/brew-*') }}
- name: Install packages that depends on Colima restored from cache
if: ${{ steps.homebrew-cache.outputs.cache-hit == 'true' }}
run: brew install --only-dependencies colima
shell: bash
- name: Relink Docker client, Docker Compose, and Colima
if: ${{ steps.homebrew-cache.outputs.cache-hit == 'true' }}
- name: Install Colima
env:
GH_TOKEN: ${{ github.token }}
run: |
brew unlink docker docker-compose colima lima
brew link docker docker-compose colima lima
LIMA_VERSION=$(gh release -R lima-vm/lima view --json tagName -q ".tagName")
curl -fsSL "https://github.com/lima-vm/lima/releases/download/${LIMA_VERSION}/lima-${LIMA_VERSION:1}-$(uname -s)-$(uname -m).tar.gz" | tar Cxzvm /usr/local
COLIMA_VERSION=$(gh release -R abiosoft/colima view --json tagName -q ".tagName")
curl -LO https://github.com/abiosoft/colima/releases/download/${COLIMA_VERSION}/colima-$(uname)-$(uname -m)
# install in $PATH
install colima-$(uname)-$(uname -m) /usr/local/bin/colima
shell: bash
- name: Install Docker client, Docker Compose, and Colima.
if: ${{ steps.homebrew-cache.outputs.cache-hit != 'true' }}
- name: Install QEMU, Docker client, and Docker Compose
env:
HOMEBREW_NO_AUTO_UPDATE: "1"
run: brew install docker docker-compose colima lima
shell: bash
- name: Manually reinstall QEMU due to bug in GH actions (see https://github.com/actions/runner-images/issues/8104)
env:
HOMEBREW_NO_INSTALL_UPGRADE: "1"
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: "1"
run: |
brew remove --ignore-dependencies qemu
cd /tmp
curl -o ./qemu.rb https://raw.githubusercontent.com/Homebrew/homebrew-core/dc0669eca9479e9eeb495397ba3a7480aaa45c2e/Formula/qemu.rb
brew install --formula ./qemu.rb
brew install docker docker-compose qemu 2>&1 | tee install.log
shell: bash
- name: Configure Docker Compose plugin
run: |
mkdir -p ~/.docker/cli-plugins
ln -sfn "$(brew --prefix)/opt/docker-compose/bin/docker-compose" ~/.docker/cli-plugins/docker-compose
shell: bash
- name: Check QEMU version
if: inputs.upgrade-qemu != 'true'
run: |
if grep -q "qemu 8.1.0 is already installed" install.log
then
echo "Detected broken QEMU bottle installed by brew, removing and reinstalling."
brew reinstall qemu
fi
shell: bash
- name: Upgrade QEMU
if: inputs.upgrade-qemu == 'true'
env:
HOMEBREW_NO_AUTO_UPDATE: "1"
HOMEBREW_NO_INSTALL_UPGRADE: "1"
run: brew upgrade qemu
shell: bash
- name: Start Colima
run: colima start
shell: bash
Expand Down

0 comments on commit 50a8f08

Please sign in to comment.