Skip to content

Commit 7fbb7be

Browse files
authored
feat: use github actions
1 parent bb84e84 commit 7fbb7be

File tree

5 files changed

+198
-0
lines changed

5 files changed

+198
-0
lines changed

.github/workflows/docker-publish.yml

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Build and Push Docker Images
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
push:
10+
branches:
11+
- "main"
12+
- "github-actions"
13+
# Publish semver tags as releases.
14+
tags:
15+
- 'v*.*.*'
16+
workflow_dispatch:
17+
pull_request:
18+
branches:
19+
- "main"
20+
21+
jobs:
22+
build:
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
packages: write
27+
# This is used to complete the identity challenge
28+
# with sigstore/fulcio when running outside of PRs.
29+
id-token: write
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v3
34+
35+
# Install the cosign tool except on PR
36+
# https://github.com/sigstore/cosign-installer
37+
- name: Install cosign
38+
if: github.event_name != 'pull_request'
39+
uses: sigstore/cosign-installer@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0
40+
with:
41+
cosign-release: 'v1.13.1'
42+
43+
# Setup QEMU for multi-arch build
44+
- name: Set up QEMU
45+
uses: docker/setup-qemu-action@v2
46+
47+
# Workaround: https://github.com/docker/build-push-action/issues/461
48+
- name: Setup Docker buildx
49+
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
50+
51+
# Login against a Docker registry except on PR
52+
# https://github.com/docker/login-action
53+
- name: Log into registry ${{ env.REGISTRY }}
54+
if: github.event_name != 'pull_request'
55+
uses: docker/login-action@v2
56+
with:
57+
username: ${{ secrets.DOCKER_USERNAME }}
58+
password: ${{ secrets.DOCKER_PASSWORD }}
59+
60+
- name: Login to GHCR
61+
if: github.event_name != 'pull_request'
62+
uses: docker/login-action@v2
63+
with:
64+
registry: ghcr.io
65+
username: ${{ github.repository_owner }}
66+
password: ${{ secrets.GITHUB_TOKEN }}
67+
68+
# Extract metadata (tags, labels) for Docker
69+
# https://github.com/docker/metadata-action
70+
- name: Extract Docker metadata
71+
id: meta
72+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
73+
with:
74+
# github.repository as <account>/<repo>
75+
images: |
76+
${{ github.repository }}
77+
ghcr.io/${{ github.repository }}
78+
tags: |
79+
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
80+
type=ref,event=branch
81+
type=ref,event=pr
82+
type=semver,pattern={{version}}
83+
type=semver,pattern={{major}}
84+
type=semver,pattern={{major}}.{{minor}}
85+
86+
# Build and push Docker image with Buildx (don't push on PR)
87+
# https://github.com/docker/build-push-action
88+
- name: Build and push Docker image
89+
id: build-and-push
90+
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
91+
with:
92+
context: .
93+
platforms: linux/amd64,linux/arm64
94+
push: ${{ github.event_name != 'pull_request' }}
95+
tags: ${{ steps.meta.outputs.tags }}
96+
labels: ${{ steps.meta.outputs.labels }}
97+
cache-from: type=gha
98+
cache-to: type=gha,mode=max
99+
100+
# Sign the resulting Docker image digest except on PRs.
101+
# This will only write to the public Rekor transparency log when the Docker
102+
# repository is public to avoid leaking data. If you would like to publish
103+
# transparency data even for private images, pass --force to cosign below.
104+
# https://github.com/sigstore/cosign
105+
- name: Sign the published Docker image
106+
if: ${{ github.event_name != 'pull_request' }}
107+
env:
108+
COSIGN_EXPERIMENTAL: "true"
109+
# This step uses the identity token to provision an ephemeral certificate
110+
# against the sigstore community Fulcio instance.
111+
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Update Docker Hub Description
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- github-actions
7+
paths:
8+
- README.md
9+
- .github/workflows/dockerhub-description.yml
10+
workflow_dispatch:
11+
12+
jobs:
13+
dockerHubDescription:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Docker Hub Description
19+
uses: peter-evans/dockerhub-description@v3
20+
with:
21+
username: ${{ secrets.DOCKER_USERNAME }}
22+
password: ${{ secrets.DOCKER_PASSWORD }}
23+
repository: ${{ github.repository }}
24+
short-description: ${{ github.event.repository.description }}
25+
enable-url-completion: true

.github/workflows/go-releaser.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Go Releaser
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
- "github-actions"
8+
# Publish semver tags as releases.
9+
tags:
10+
- 'v*.*.*'
11+
workflow_dispatch:
12+
pull_request:
13+
branches:
14+
- "main"
15+
16+
permissions:
17+
contents: write
18+
19+
jobs:
20+
goreleaser:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Set up Go
29+
uses: actions/setup-go@v4
30+
with:
31+
go-version: 1.19
32+
33+
- name: Run GoReleaser
34+
uses: goreleaser/goreleaser-action@v4
35+
with:
36+
# either 'goreleaser' (default) or 'goreleaser-pro'
37+
distribution: goreleaser
38+
version: latest
39+
args: release --clean
40+
workdir: ./cmd/ovh-mks-exporter
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
.env
2+
3+
dist/
4+
vendor/

.goreleaser.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
before:
2+
hooks:
3+
- go mod vendor
4+
builds:
5+
- binary: bin/ovh-mks-exporter
6+
main: ./cmd/ovh-mks-exporter/main.go
7+
env:
8+
- CGO_ENABLED=0
9+
flags:
10+
- -mod=vendor
11+
goos:
12+
- linux
13+
goarch:
14+
- amd64
15+
- arm64
16+
checksum:
17+
name_template: 'checksums.txt'

0 commit comments

Comments
 (0)