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

Better sandboxed workflow and enhanced cross compilation #9744

Merged
merged 1 commit into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
bin/
dist/
250 changes: 171 additions & 79 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,125 +1,217 @@
name: Continuous integration
name: ci

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
push:
branches:
- v2
- 'v2'
tags:
- 'v*'
pull_request:
workflow_dispatch:
inputs:
debug_enabled:
description: 'To run with tmate enter "debug_enabled"'
required: false
default: "false"

env:
GO_VERSION: 1.18.5
DOCKER_CLI_VERSION: 20.10.17
GO_VERSION: "1.18.5" # for non sandboxed e2e tests
DESTDIR: "./bin"
DOCKER_CLI_VERSION: "20.10.17"

jobs:
lint:
name: Lint
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.platforms.outputs.matrix }}
steps:
- name: Checkout code into the Go module directory
-
name: Checkout
uses: actions/checkout@v3
-
name: Create matrix
id: platforms
run: |
echo ::set-output name=matrix::$(docker buildx bake binary-cross --print | jq -cr '.target."binary-cross".platforms')
-
name: Show matrix
run: |
echo ${{ steps.platforms.outputs.matrix }}

- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- name: Validate go-mod, license headers and docs are up-to-date
run: make validate

- name: Run golangci-lint
env:
BUILD_TAGS: e2e
uses: golangci/golangci-lint-action@v3
with:
version: v1.47.3
args: --timeout=180s

# only on main branch, costs too much for the gain on every PR
validate-cross-build:
name: Validate cross build
validate:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
strategy:
fail-fast: false
matrix:
target:
- lint
- validate-go-mod
- validate-headers
- validate-docs
steps:
- name: Checkout code into the Go module directory
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Run
run: |
make ${{ matrix.target }}

- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v3
binary:
runs-on: ubuntu-latest
needs:
- prepare
strategy:
fail-fast: false
matrix:
platform: ${{ fromJson(needs.prepare.outputs.matrix) }}
steps:
-
name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Build
uses: docker/bake-action@v2
with:
go-version: ${{ env.GO_VERSION }}
cache: true

# Ensure we don't discover cross platform build issues at release time.
# Time used to build linux here is gained back in the build for local E2E step
- name: Build packages
run: make -f builder.Makefile cross
targets: release
set: |
*.platform=${{ matrix.platform }}
*.cache-from=type=gha,scope=binary-${{ env.PLATFORM_PAIR }}
*.cache-to=type=gha,scope=binary-${{ env.PLATFORM_PAIR }},mode=max
-
name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: compose
path: ${{ env.DESTDIR }}/*
if-no-files-found: error

build-plugin:
name: Build and tests in plugin mode
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code into the Go module directory
-
name: Checkout
uses: actions/checkout@v3

- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Test
uses: docker/bake-action@v2
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- name: Setup docker CLI
run: |
curl https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_CLI_VERSION}.tgz | tar xz
sudo cp ./docker/docker /usr/bin/ && rm -rf docker && docker version

- name: Test
run: make -f builder.Makefile test

- name: Build for local E2E
env:
BUILD_TAGS: e2e
run: make GIT_TAG=e2e-PR-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }} -f builder.Makefile compose-plugin
targets: test
set: |
*.cache-from=type=gha,scope=test
*.cache-to=type=gha,scope=test

- name: E2E Test in plugin mode
run: make e2e-compose

build-standalone:
name: Build and tests in standalone mode
e2e:
runs-on: ubuntu-latest
env:
DESTDIR: "./bin/build"
strategy:
fail-fast: false
matrix:
mode:
- plugin
- standalone
steps:
- name: Checkout code into the Go module directory
-
name: Checkout
uses: actions/checkout@v3

- name: Set up Go ${{ env.GO_VERSION }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- name: Setup docker CLI
-
name: Setup docker CLI
run: |
curl https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_CLI_VERSION}.tgz | tar xz
sudo cp ./docker/docker /usr/bin/ && rm -rf docker && docker version

- name: Build for local E2E
-
name: Build
uses: docker/bake-action@v2
with:
targets: binary
set: |
*.cache-from=type=gha,scope=binary-linux-amd64
*.cache-from=type=gha,scope=binary-e2e-${{ matrix.mode }}
*.cache-to=type=gha,scope=binary-e2e-${{ matrix.mode }},mode=max
env:
BUILD_TAGS: e2e
run: make GIT_TAG=e2e-PR-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }} -f builder.Makefile compose-plugin

- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
-
name: Setup tmate session
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
uses: mxschmitt/action-tmate@8b4e4ac71822ed7e0ad5fb3d1c33483e9e8fb270 # v3.11
with:
limit-access-to-actor: true
github-token: ${{ secrets.GITHUB_TOKEN }}
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}

- name: E2E Test in standalone mode
-
name: Test plugin mode
if: ${{ matrix.mode == 'plugin' }}
run: |
make e2e-compose
-
name: Test standalone mode
if: ${{ matrix.mode == 'standalone' }}
run: |
rm -f /usr/local/bin/docker-compose
cp bin/docker-compose /usr/local/bin
cp bin/build/docker-compose /usr/local/bin
make e2e-compose-standalone

release:
runs-on: ubuntu-latest
needs:
- binary
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Download artifacts
uses: actions/download-artifact@v3
with:
name: compose
path: ${{ env.DESTDIR }}
-
name: License
run: cp packaging/* ${{ env.DESTDIR }}/
-
name: List artifacts
run: |
tree -nh ${{ env.DESTDIR }}
-
name: Check artifacts
run: |
find ${{ env.DESTDIR }} -type f -exec file -e ascii -- {} +
-
name: GitHub Release
if: startsWith(github.ref, 'refs/tags/v')
uses: ncipollo/release-action@58ae73b360456532aafd58ee170c045abbeaee37 # v1.10.0
with:
artifacts: ${{ env.DESTDIR }}/*
generateReleaseNotes: true
draft: true
token: ${{ secrets.GITHUB_TOKEN }}
45 changes: 0 additions & 45 deletions .github/workflows/release.yaml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
bin/
dist/
/.vscode/
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
run:
concurrency: 2
timeout: 10m
linters:
enable-all: false
disable-all: true
Expand Down
5 changes: 3 additions & 2 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Once you have the prerequisites installed, you can build the CLI using:
make
```

This will output a `docker-compose` CLI plugin for your host machine in `./bin`.
This will output a `docker-compose` CLI plugin for your host machine in
`./bin/build`.

You can statically cross compile the CLI for Windows, macOS, and Linux using the
`cross` target.
Expand All @@ -38,7 +39,6 @@ If you need to update a golden file simply do `go test ./... -test.update-golden
To run e2e tests, the Compose CLI binary need to be build. All the commands to run e2e tests propose a version
with the prefix `build-and-e2e` to first build the CLI before executing tests.


Note that this requires a local Docker Engine to be running.

#### Whole end-to-end tests suite
Expand Down Expand Up @@ -76,6 +76,7 @@ make e2e-compose-standalone
```

Or if you need to build the CLI, run:

```console
make build-and-e2e-compose-standalone
```
Expand Down
Loading