Skip to content

Commit 299d43e

Browse files
authored
Refactor CI and dev workflow with buildx bake (#99)
* Upload artifacts * Add `image-local` target * Single job for artifacts and image * Add armv5 artifact Co-authored-by: CrazyMax <[email protected]>
1 parent a62b403 commit 299d43e

20 files changed

+462
-247
lines changed

.dockerignore

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
/.idea
22
/*.iml
33

4-
/.dev
5-
/.git
6-
/.github
7-
/.res
4+
.dev
85
/bin
96
/dist
10-
/docs
11-
/.editorconfig
12-
/.gitignore
13-
/.goreleaser.yml
14-
/CHANGELOG.md
15-
/LICENSE
16-
/README.md
7+
/site

.github/CONTRIBUTING.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Contributing
2+
3+
Hi there! I'm thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
4+
5+
Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license)
6+
to the public under the [project's open source license](../LICENSE).
7+
8+
## Submitting a pull request
9+
10+
1. [Fork](https://github.com/crazy-max/swarm-cronjob/fork) and clone the repository
11+
2. Configure and install the dependencies: `go mod download`
12+
3. Create a new branch: `git checkout -b my-branch-name`
13+
4. Make your changes
14+
5. Validate: `docker buildx bake validate`
15+
6. Build the project: `docker buildx bake artifact-all image-all`
16+
7. Push to your fork and [submit a pull request](https://github.com/crazy-max/swarm-cronjob/compare)
17+
8. Pat your self on the back and wait for your pull request to be reviewed and merged.
18+
19+
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
20+
21+
* Make sure the `README.md` and any other relevant **documentation are kept up-to-date**.
22+
* I try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
23+
* 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**.
24+
* Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
25+
26+
## Resources
27+
28+
* [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
29+
* [Using Pull Requests](https://docs.github.com/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/about-pull-requests)
30+
* [GitHub Help](https://docs.github.com)

.github/dependabot.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ updates:
1010
labels:
1111
- ":game_die: dependencies"
1212
- ":robot: bot"
13-
- package-ecosystem: "docker"
14-
open-pull-requests-limit: 10
15-
directory: "/docs"
16-
schedule:
17-
interval: "daily"
18-
time: "08:00"
19-
timezone: "Europe/Paris"
20-
labels:
21-
- ":game_die: dependencies"
22-
- ":robot: bot"
2313
- package-ecosystem: "github-actions"
2414
open-pull-requests-limit: 10
2515
directory: "/"

.github/workflows/build.yml

Lines changed: 45 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches:
66
- 'master'
7-
- 'v*'
87
tags:
98
- 'v*'
109
paths-ignore:
@@ -15,70 +14,25 @@ on:
1514
pull_request:
1615
branches:
1716
- 'master'
18-
- 'v*'
1917
paths-ignore:
2018
- '**.md'
2119
- '.github/workflows/docs.yml'
2220
- 'docs/**'
2321
- 'mkdocs.yml'
2422

23+
env:
24+
DOCKERHUB_SLUG: crazymax/swarm-cronjob
25+
GHCR_SLUG: ghcr.io/crazy-max/swarm-cronjob
26+
2527
jobs:
26-
go:
28+
build:
2729
runs-on: ubuntu-latest
2830
steps:
2931
-
3032
name: Checkout
3133
uses: actions/checkout@v2
32-
-
33-
name: Prepare
34-
id: prep
35-
run: |
36-
if [[ $GITHUB_REF == refs/tags/* ]]; then
37-
echo ::set-output name=tag_name::${GITHUB_REF#refs/tags/}
38-
fi
39-
-
40-
name: Set up Go
41-
uses: actions/setup-go@v2
42-
with:
43-
go-version: 1.15
44-
-
45-
name: Cache Go modules
46-
uses: actions/cache@v2
47-
with:
48-
path: ~/go/pkg/mod
49-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
50-
restore-keys: |
51-
${{ runner.os }}-go-
52-
-
53-
name: GoReleaser
54-
uses: goreleaser/goreleaser-action@v2
5534
with:
56-
version: latest
57-
args: release --skip-publish --rm-dist
58-
-
59-
name: GitHub Release
60-
uses: softprops/action-gh-release@v1
61-
if: startsWith(github.ref, 'refs/tags/')
62-
with:
63-
draft: true
64-
files: |
65-
dist/checksums.txt
66-
dist/*.tar.gz
67-
dist/*.zip
68-
name: ${{ steps.prep.outputs.tag_name }}
69-
env:
70-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71-
72-
docker:
73-
runs-on: ubuntu-latest
74-
needs: go
75-
env:
76-
DOCKERHUB_SLUG: crazymax/swarm-cronjob
77-
GHCR_SLUG: ghcr.io/crazy-max/swarm-cronjob
78-
steps:
79-
-
80-
name: Checkout
81-
uses: actions/checkout@v2
35+
fetch-depth: 0
8236
-
8337
name: Docker meta
8438
id: docker_meta
@@ -90,14 +44,19 @@ jobs:
9044
tag-semver: |
9145
{{version}}
9246
tag-edge: true
47+
label-custom: |
48+
org.opencontainers.image.title=swarm-cronjob
49+
org.opencontainers.image.description=Create jobs on a time-based schedule on Swarm
50+
org.opencontainers.image.vendor=CrazyMax
9351
-
9452
name: Set up QEMU
9553
uses: docker/setup-qemu-action@v1
9654
-
9755
name: Set up Docker Buildx
9856
uses: docker/setup-buildx-action@v1
9957
with:
100-
buildkitd-flags: "--debug"
58+
version: latest
59+
buildkitd-flags: --debug
10160
-
10261
name: Login to DockerHub
10362
if: github.event_name != 'pull_request'
@@ -114,21 +73,41 @@ jobs:
11473
username: ${{ secrets.GHCR_USERNAME }}
11574
password: ${{ secrets.GHCR_TOKEN }}
11675
-
117-
name: Build
118-
uses: docker/build-push-action@v2
76+
name: Build artifacts
77+
uses: crazy-max/ghaction-docker-buildx-bake@v1
11978
with:
120-
context: .
121-
file: ./Dockerfile
122-
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x
79+
targets: artifact-all
80+
-
81+
name: Move artifacts
82+
run: |
83+
mv ./dist/**/* ./dist/
84+
-
85+
name: Upload artifacts
86+
uses: actions/upload-artifact@v2
87+
with:
88+
name: swarm-cronjob
89+
path: ./dist/*
90+
if-no-files-found: error
91+
-
92+
name: Build image
93+
uses: crazy-max/ghaction-docker-buildx-bake@v1
94+
with:
95+
files: |
96+
./docker-bake.hcl
97+
${{ steps.docker_meta.outputs.bake-file }}
98+
targets: image-all
12399
push: ${{ github.event_name != 'pull_request' }}
124-
tags: ${{ steps.docker_meta.outputs.tags }}
125-
build-args: |
126-
VERSION=${{ steps.docker_meta.outputs.version }}
127-
labels: |
128-
${{ steps.docker_meta.outputs.labels }}
129-
org.opencontainers.image.title=swarm-cronjob
130-
org.opencontainers.image.description=Create jobs on a time-based schedule on Swarm
131-
org.opencontainers.image.vendor=CrazyMax
100+
-
101+
name: GitHub Release
102+
uses: softprops/action-gh-release@v1
103+
if: startsWith(github.ref, 'refs/tags/')
104+
with:
105+
draft: true
106+
files: |
107+
dist/*.tar.gz
108+
dist/*.zip
109+
env:
110+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132111
-
133112
name: Check manifest
134113
if: github.event_name != 'pull_request'

.github/workflows/docs.yml

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches:
66
- 'master'
7-
- 'v*'
87
tags:
98
- 'v*'
109
paths:
@@ -15,7 +14,6 @@ on:
1514
pull_request:
1615
branches:
1716
- 'master'
18-
- 'v*'
1917
paths:
2018
- '.github/workflows/docs.yml'
2119
- 'docs/**'
@@ -32,35 +30,23 @@ jobs:
3230
with:
3331
fetch-depth: 0
3432
-
35-
name: Prepare
36-
id: prep
37-
run: |
38-
VERSION=edge
39-
RELEASE=false
40-
if [[ $GITHUB_REF == refs/tags/* ]]; then
41-
VERSION=${GITHUB_REF#refs/tags/v}
42-
fi
43-
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
44-
RELEASE=true
45-
fi
46-
echo ::set-output name=release::${RELEASE}
47-
-
48-
name: Build mkdocs Docker image
49-
run: |
50-
docker build -t mkdocs -f ./docs/Dockerfile ./
33+
name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v1
35+
with:
36+
version: latest
5137
-
5238
name: Build docs
53-
run: |
54-
docker run --rm -v "$(pwd):/docs" mkdocs build --strict
55-
sudo chown -R $(id -u):$(id -g) ./site
39+
uses: crazy-max/ghaction-docker-buildx-bake@v1
40+
with:
41+
targets: docs
5642
-
5743
name: Check GitHub Pages status
5844
uses: crazy-max/ghaction-github-status@v2
5945
with:
6046
pages_threshold: major_outage
6147
-
6248
name: Deploy
63-
if: github.event_name != 'pull_request' && (endsWith(github.ref, github.event.repository.default_branch) || steps.prep.outputs.release == 'true')
49+
if: github.event_name != 'pull_request'
6450
uses: crazy-max/ghaction-github-pages@v2
6551
with:
6652
target_branch: gh-pages

.github/workflows/test.yml renamed to .github/workflows/e2e.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: test
1+
name: e2e
22

33
on:
44
push:
@@ -15,17 +15,19 @@ on:
1515
- '**.md'
1616

1717
jobs:
18-
test:
18+
e2e:
1919
runs-on: ubuntu-latest
2020
steps:
2121
-
2222
name: Checkout
2323
uses: actions/checkout@v2
24+
with:
25+
fetch-depth: 0
2426
-
2527
name: Prepare
2628
id: prep
2729
run: |
28-
echo ::set-output name=build_tag::test
30+
echo ::set-output name=build_tag::crazymax/swarm-cronjob:local
2931
echo ::set-output name=service_name::swarm-cronjob
3032
echo ::set-output name=running_timeout::120
3133
echo ::set-output name=running_log_check::Number of cronjob tasks: 6
@@ -37,12 +39,9 @@ jobs:
3739
uses: docker/setup-buildx-action@v1
3840
-
3941
name: Build
40-
uses: docker/build-push-action@v2
42+
uses: crazy-max/ghaction-docker-buildx-bake@v1
4143
with:
42-
context: .
43-
file: ./Dockerfile
44-
load: true
45-
tags: ${{ steps.prep.outputs.build_tag }}
44+
targets: image-local
4645
-
4746
name: Swarm init
4847
run: |

.github/workflows/gosum.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)