Skip to content

Commit

Permalink
enhance gha pipeline for release
Browse files Browse the repository at this point in the history
  • Loading branch information
wagoodman committed Nov 9, 2019
1 parent 9a34db4 commit 7a5992f
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 133 deletions.
130 changes: 130 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: 'app-pipeline'
on: [ push, pull_request ]
env:
DOCKER_CLI_VERSION: "19.03.1"
jobs:
unit-test:
strategy:
matrix:
go-version: [1.12.x, 1.13.x]
# todo: support windows
platform: [ubuntu-latest, macos-latest]
# platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:

- uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}

- uses: actions/checkout@v1

- name: Cache go dependencies
id: unit-cache-go-dependencies
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install go dependencies
if: steps.unit-cache-go-dependencies.outputs.cache-hit != 'true'
run: go get ./...

- name: Test
run: make ci-test

build-artifacts:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v1
with:
go-version: '1.13.x'

- uses: actions/checkout@v1

- name: Install go tools
run: make ci-install-go-tools

- name: Cache go dependencies
id: package-cache-go-dependencies
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install dependencies
if: steps.package-cache-go-dependencies.outputs.cache-hit != 'true'
run: go get ./...

# todo: test gofmt

- name: Lint
run: golangci-lint run -v

- name: Build snapshot artifacts
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --snapshot --skip-publish --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: docker images wagoodman/dive

# todo: compare against known json output in shared volume
- name: Test production image
run: make ci-test-production-image

- uses: actions/upload-artifact@master
with:
name: artifacts
path: dist

release:
needs: [ build-artifacts, unit-test ]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:

- uses: actions/setup-go@v1
with:
go-version: '1.13.x'

- uses: actions/checkout@v1

- name: Cache go dependencies
id: release-cache-go-dependencies
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install dependencies
if: steps.release-cache-go-dependencies.outputs.cache-hit != 'true'
run: go get ./...

- name: Docker login
run: make ci-docker-login
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

- name: Publish GitHub release
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Docker logout
run: make ci-docker-logout

- name: Smoke test published image
run: make ci-test-production-image
38 changes: 0 additions & 38 deletions .github/workflows/push.yml

This file was deleted.

25 changes: 0 additions & 25 deletions .goreleaser.docker.yml

This file was deleted.

27 changes: 20 additions & 7 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ builds:
- amd64
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.buildTime={{.Date}}`.

brews:
- github:
owner: wagoodman
name: homebrew-dive
homepage: "https://github.com/wagoodman/dive/"
description: "A tool for exploring each layer in a docker image"

archives:
- format: tar.gz
format_overrides:
Expand All @@ -24,12 +31,18 @@ nfpms:
maintainer: Alex Goodman
homepage: https://github.com/wagoodman/dive/
formats:
- deb
- rpm
- deb

brews:
- github:
owner: wagoodman
name: homebrew-dive
homepage: "https://github.com/wagoodman/dive/"
description: "A tool for exploring each layer in a docker image"
dockers:
-
binaries:
- dive
dockerfile: Dockerfile
image_templates:
- "wagoodman/dive:latest"
- "wagoodman/dive:{{ .Tag }}"
- "wagoodman/dive:v{{ .Major }}"
- "wagoodman/dive:v{{ .Major }}.{{ .Minor }}"
build_flag_templates:
- "--build-arg=DOCKER_CLI_VERSION={{.Env.DOCKER_CLI_VERSION}}"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:3.10

ARG DOCKER_CLI_VERSION=19.03.1
ARG DOCKER_CLI_VERSION=${DOCKER_CLI_VERSION}
RUN wget -O- https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_CLI_VERSION}.tgz | \
tar -xzf - docker/docker --strip-component=1 && \
mv docker /usr/local/bin
Expand Down
72 changes: 35 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,61 @@ BIN = dive
BUILD_DIR = ./dist/dive_linux_amd64
BUILD_PATH = $(BUILD_DIR)/$(BIN)
PWD := ${CURDIR}
PRODUCTION_REGISTRY = docker.io
TEST_IMAGE = busybox:latest

all: clean build

## For CI

ci-test:
go test -cover -v -race ./...

ci-install-go-tools:
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sudo sh -s -- -b /usr/local/bin/ latest

ci-docker-login:
echo '${DOCKER_PASSWORD}' | docker login -u '${DOCKER_USERNAME}' --password-stdin '${PRODUCTION_REGISTRY}'

ci-docker-logout:
docker logout '${PRODUCTION_REGISTRY}'

ci-publish-release:
goreleaser --rm-dist

# todo: add --pull=never when supported by host box
ci-test-production-image:
docker run \
--rm \
-t \
-v //var/run/docker.sock://var/run/docker.sock \
'${PRODUCTION_REGISTRY}/wagoodman/dive:latest' \
'${TEST_IMAGE}' \
--ci

## For development

run: build
$(BUILD_PATH) build -t dive-example:latest -f .data/Dockerfile.example .

run-large: build
$(BUILD_PATH) amir20/clashleaders:latest

run-podman: build
$(BUILD_PATH) localhost/dive-example:latest --source podman

run-podman-build: build
podman build -t dive-example:latest -f .data/Dockerfile.example .
$(BUILD_PATH) localhost/dive-example:latest --source podman

$(BUILD_PATH) localhost/dive-example:latest --engine podman

run-podman-large: build
$(BUILD_PATH) docker.io/amir20/clashleaders:latest --source podman
$(BUILD_PATH) docker.io/amir20/clashleaders:latest --engine podman

run-ci: build
CI=true $(BUILD_PATH) dive-example:latest --ci-config .data/.dive-ci

build:
go build -o $(BUILD_PATH)

release: test-coverage validate
./.scripts/tag.sh
goreleaser --rm-dist

install:
go install ./...

ci: clean validate test-coverage

test: build
go test -cover -v -race ./...

test-coverage: build
./.scripts/test-coverage.sh

validate:
grep -R 'const allowTestDataCapture = false' runtime/ui/viewmodel
go vet ./...
@! gofmt -s -l . 2>&1 | grep -vE '^\.git/' | grep -vE '^\.cache/'
golangci-lint run

lint: build
golint -set_exit_status $$(go list ./...)

generate-test-data:
docker build -t dive-test:latest -f .data/Dockerfile.test-image . && docker image save -o .data/test-docker-image.tar dive-test:latest && echo "Exported test data!"

setup-ci:
sudo apt update && sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev
go get ./...
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b /go/bin v1.18.0
docker build -t dive-test:latest -f .data/Dockerfile.test-image . && docker image save -o .data/test-docker-image.tar dive-test:latest && echo 'Exported test data!'

dev:
docker run -ti --rm -v $(PWD):/app -w /app -v dive-pkg:/go/pkg/ golang:1.13 bash
Expand All @@ -67,4 +65,4 @@ clean:
rm -rf dist
go clean

.PHONY: build install test lint clean release validate generate-test-data test-coverage ci dev

25 changes: 0 additions & 25 deletions docker.sh

This file was deleted.

0 comments on commit 7a5992f

Please sign in to comment.