Skip to content

Commit

Permalink
feat: basic ci
Browse files Browse the repository at this point in the history
  • Loading branch information
molu8bits committed May 26, 2023
1 parent 093fafe commit bdcbf12
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 20 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/docker-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Publish Docker Images
on:
push:
branches:
- master
- develop
- "feature/ci-actions"
release:
types:
- published
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
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: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
molu8bits/s3bucket_exporter
tags: |
type=semver,pattern={{version}}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name == 'release' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.output.labels }}
26 changes: 26 additions & 0 deletions .github/workflows/frogbot-scan-pr-go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Frogbot Scan Pull Request"
on:
pull_request_target:
types: [opened, synchronize]
permissions:
pull-requests: write
contents: read
jobs:
scan-pull-request:
runs-on: ubuntu-latest
environment: frogbot
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x

- uses: jfrog/frogbot@v2
env:
JF_URL: ${{ secrets.JF_URL }}
JF_ACCESS_TOKEN: ${{ secrets.JF_ACCESS_TOKEN }}
JF_GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46 changes: 46 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Release Go Binaries

on:
release:
types: [created]
workflow_dispatch:

permissions:
contents: write

env:
CMD_PATH: ./


jobs:
releases-matrix:
name: Release Matrix
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: ["386", amd64]
exclude:
- goarch: "386"
goos: windows
- goarch: "386"
goos: darwin
steps:
- uses: actions/checkout@v3

- name: Set APP_VERSION env
run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV}
- name: Set BUILD_TIME env
run: echo BUILD_TIME=$(date) >> ${GITHUB_ENV}
- name: Environment Printer
uses: managedkaos/[email protected]

- uses: wangyoucao577/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
project_path: "${{ env.CMD_PATH }}"
build_flags: -v
ldflags: -X "main.appVersion=${{ env.APP_VERSION }}" -X "main.buildTime=${{ env.BUILD_TIME }}" -X main.gitCommit=${{ github.sha }} -X main.gitRef=${{ github.ref }}
binary_name: "s3bucket_exporter"
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

# molu8bits
s3bucket_exporter
25 changes: 5 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
FROM docker.io/library/golang:1.14 AS builder

# Dependencies
RUN apt-get update \
&& apt-get install -y bzr \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir /build
FROM golang:1.20 AS builder
WORKDIR /build

RUN go get github.com/aws/aws-sdk-go \
&& go get github.com/prometheus/client_golang/prometheus \
&& go get github.com/Sirupsen/logrus

# Build
COPY ./*.go /build/
COPY controllers /build/controllers

RUN go build ./main.go
RUN cp ./main /bin/s3bucket_exporter
COPY ./ /build
RUN go get -d -v
RUN CGO_ENABLED=0 GOOS=linux go build

FROM docker.io/library/debian:buster-slim
COPY --from=builder /bin/s3bucket_exporter /bin/s3bucket_exporter
COPY --from=builder /build/s3bucket_exporter /bin/s3bucket_exporter
RUN apt-get update && apt-get install -y curl
WORKDIR /tmp
ENTRYPOINT ["/bin/s3bucket_exporter"]

0 comments on commit bdcbf12

Please sign in to comment.