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

Improve resliency of action #19

Merged
merged 24 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
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/cache@v3.3.1
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