Skip to content

Commit

Permalink
Refactor CI and dev workflow with buildx bake
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Jan 3, 2021
1 parent a62b403 commit cceb563
Show file tree
Hide file tree
Showing 20 changed files with 462 additions and 247 deletions.
13 changes: 2 additions & 11 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
/.idea
/*.iml

/.dev
/.git
/.github
/.res
.dev
/bin
/dist
/docs
/.editorconfig
/.gitignore
/.goreleaser.yml
/CHANGELOG.md
/LICENSE
/README.md
/site
30 changes: 30 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Contributing

Hi there! I'm thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.

Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license)
to the public under the [project's open source license](../LICENSE).

## Submitting a pull request

1. [Fork](https://github.com/crazy-max/swarm-cronjob/fork) and clone the repository
2. Configure and install the dependencies: `go mod download`
3. Create a new branch: `git checkout -b my-branch-name`
4. Make your changes
5. Validate: `docker buildx bake validate`
6. Build the project: `docker buildx bake artifact-all image-all`
7. Push to your fork and [submit a pull request](https://github.com/crazy-max/swarm-cronjob/compare)
8. Pat your self on the back and wait for your pull request to be reviewed and merged.

Here are a few things you can do that will increase the likelihood of your pull request being accepted:

* Make sure the `README.md` and any other relevant **documentation are kept up-to-date**.
* I try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
* Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as **separate pull requests**.
* Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).

## Resources

* [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
* [Using Pull Requests](https://docs.github.com/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/about-pull-requests)
* [GitHub Help](https://docs.github.com)
10 changes: 0 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ updates:
labels:
- ":game_die: dependencies"
- ":robot: bot"
- package-ecosystem: "docker"
open-pull-requests-limit: 10
directory: "/docs"
schedule:
interval: "daily"
time: "08:00"
timezone: "Europe/Paris"
labels:
- ":game_die: dependencies"
- ":robot: bot"
- package-ecosystem: "github-actions"
open-pull-requests-limit: 10
directory: "/"
Expand Down
111 changes: 45 additions & 66 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- 'master'
- 'v*'
tags:
- 'v*'
paths-ignore:
Expand All @@ -15,70 +14,25 @@ on:
pull_request:
branches:
- 'master'
- 'v*'
paths-ignore:
- '**.md'
- '.github/workflows/docs.yml'
- 'docs/**'
- 'mkdocs.yml'

env:
DOCKERHUB_SLUG: crazymax/swarm-cronjob
GHCR_SLUG: ghcr.io/crazy-max/swarm-cronjob

jobs:
go:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Prepare
id: prep
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo ::set-output name=tag_name::${GITHUB_REF#refs/tags/}
fi
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
-
name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
-
name: GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --skip-publish --rm-dist
-
name: GitHub Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
files: |
dist/checksums.txt
dist/*.tar.gz
dist/*.zip
name: ${{ steps.prep.outputs.tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker:
runs-on: ubuntu-latest
needs: go
env:
DOCKERHUB_SLUG: crazymax/swarm-cronjob
GHCR_SLUG: ghcr.io/crazy-max/swarm-cronjob
steps:
-
name: Checkout
uses: actions/checkout@v2
fetch-depth: 0
-
name: Docker meta
id: docker_meta
Expand All @@ -90,14 +44,19 @@ jobs:
tag-semver: |
{{version}}
tag-edge: true
label-custom: |
org.opencontainers.image.title=swarm-cronjob
org.opencontainers.image.description=Create jobs on a time-based schedule on Swarm
org.opencontainers.image.vendor=CrazyMax
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
buildkitd-flags: "--debug"
version: latest
buildkitd-flags: --debug
-
name: Login to DockerHub
if: github.event_name != 'pull_request'
Expand All @@ -114,21 +73,41 @@ jobs:
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
-
name: Build
uses: docker/build-push-action@v2
name: Build artifacts
uses: crazy-max/ghaction-docker-buildx-bake@v1
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x
targets: artifact-all
-
name: Move artifacts
run: |
mv ./dist/**/* ./dist/
-
name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: swarm-cronjob
path: ./dist/*
if-no-files-found: error
-
name: Build image
uses: crazy-max/ghaction-docker-buildx-bake@v1
with:
files: |
./docker-bake.hcl
${{ steps.docker_meta.outputs.bake-file }}
targets: image-all
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
build-args: |
VERSION=${{ steps.docker_meta.outputs.version }}
labels: |
${{ steps.docker_meta.outputs.labels }}
org.opencontainers.image.title=swarm-cronjob
org.opencontainers.image.description=Create jobs on a time-based schedule on Swarm
org.opencontainers.image.vendor=CrazyMax
-
name: GitHub Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
files: |
dist/*.tar.gz
dist/*.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Check manifest
if: github.event_name != 'pull_request'
Expand Down
30 changes: 8 additions & 22 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- 'master'
- 'v*'
tags:
- 'v*'
paths:
Expand All @@ -15,7 +14,6 @@ on:
pull_request:
branches:
- 'master'
- 'v*'
paths:
- '.github/workflows/docs.yml'
- 'docs/**'
Expand All @@ -32,35 +30,23 @@ jobs:
with:
fetch-depth: 0
-
name: Prepare
id: prep
run: |
VERSION=edge
RELEASE=false
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
RELEASE=true
fi
echo ::set-output name=release::${RELEASE}
-
name: Build mkdocs Docker image
run: |
docker build -t mkdocs -f ./docs/Dockerfile ./
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
-
name: Build docs
run: |
docker run --rm -v "$(pwd):/docs" mkdocs build --strict
sudo chown -R $(id -u):$(id -g) ./site
uses: crazy-max/ghaction-docker-buildx-bake@v1
with:
targets: docs
-
name: Check GitHub Pages status
uses: crazy-max/ghaction-github-status@v2
with:
pages_threshold: major_outage
-
name: Deploy
if: github.event_name != 'pull_request' && (endsWith(github.ref, github.event.repository.default_branch) || steps.prep.outputs.release == 'true')
if: github.event_name != 'pull_request'
uses: crazy-max/ghaction-github-pages@v2
with:
target_branch: gh-pages
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/test.yml → .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test
name: e2e

on:
push:
Expand All @@ -15,17 +15,19 @@ on:
- '**.md'

jobs:
test:
e2e:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Prepare
id: prep
run: |
echo ::set-output name=build_tag::test
echo ::set-output name=build_tag::crazymax/swarm-cronjob:local
echo ::set-output name=service_name::swarm-cronjob
echo ::set-output name=running_timeout::120
echo ::set-output name=running_log_check::Number of cronjob tasks: 6
Expand All @@ -37,12 +39,9 @@ jobs:
uses: docker/setup-buildx-action@v1
-
name: Build
uses: docker/build-push-action@v2
uses: crazy-max/ghaction-docker-buildx-bake@v1
with:
context: .
file: ./Dockerfile
load: true
tags: ${{ steps.prep.outputs.build_tag }}
targets: image-local
-
name: Swarm init
run: |
Expand Down
44 changes: 0 additions & 44 deletions .github/workflows/gosum.yml

This file was deleted.

Loading

0 comments on commit cceb563

Please sign in to comment.