Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
identw committed May 15, 2024
1 parent 37c159e commit 19f76b0
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 67 deletions.
132 changes: 65 additions & 67 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,97 +4,95 @@ on:
tags:
- 'v*'
jobs:
build_and_release:
name: build_and_release
test_build:
name: test_build
runs-on: ubuntu-22.04
steps:
- name: clone
uses: actions/checkout@main
- name: install depends
run: |
go mod download
mkdir artifacts
- name: Setup Go
uses: actions/setup-go@main
with:
go-version: 1.22
- name: build
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o artifacts/custom-exporter
create_release:
name: create_release
runs-on: ubuntu-22.04
needs: [test_build]
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
uses: actions/create-release@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

upload_release:
needs: [create_release]
name: build_and_release
runs-on: ubuntu-22.04
strategy:
matrix:
arch: [amd64, arm64, arm7]
steps:
- name: clone
uses: actions/checkout@main
- name: install depends
run: |
go mod tidy
go mod download
mkdir artifacts
- name: Setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@main
with:
go-version: 1.22

- name: build
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o artifacts/custom-exporter-amd64 .
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags="-s -w" -o artifacts/custom-exporter-386 .
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o artifacts/custom-exporter-arm64 .
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-s -w" -o artifacts/custom-exporter-arm7 .
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags="-s -w" -o artifacts/custom-exporter-arm6 .
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -ldflags="-s -w" -o artifacts/custom-exporter-arm5 .
- name: Upload relerase amd64
id: upload-release-asset-amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./artifacts/custom-exporter-amd64
asset_name: custom-exporter-amd64
asset_content_type: application/x-elf
- name: Upload relerase 386
id: upload-release-asset-386
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./artifacts/custom-exporter-386
asset_name: custom-exporter-386
asset_content_type: application/x-elf
- name: Upload relerase arm64
id: upload-release-asset-arm64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./artifacts/custom-exporter-arm64
asset_name: custom-exporter-arm64
asset_content_type: application/x-elf
- name: Upload relerase arm7
id: upload-release-asset-arm7
uses: actions/upload-release-asset@v1
CGO_ENABLED=0 GOOS=linux GOARCH=${{ matrix.arch }} go build -ldflags="-s -w" -o artifacts/custom-exporter-${{ matrix.arch }} .
- name: Upload release
id: upload-release-asset
uses: actions/upload-release-asset@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./artifacts/custom-exporter-arm7
asset_name: custom-exporter-arm7
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./artifacts/custom-exporter-${{ matrix.arch }}
asset_name: custom-exporter-${{ matrix.arch }}
asset_content_type: application/x-elf
- name: Upload relerase arm6
id: upload-release-asset-arm6
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

container_image:
name: container_image
runs-on: ubuntu-22.04
needs: [upload_release]
steps:
- name: Checkout code
uses: actions/checkout@main
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./artifacts/custom-exporter-arm6
asset_name: custom-exporter-arm6
asset_content_type: application/x-elf
- name: Upload relerase arm5
id: upload-release-asset-arm5
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./artifacts/custom-exporter-arm5
asset_name: custom-exporter-arm5
asset_content_type: application/x-elf
context: .
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ghcr.io/${{ github.repository_owner }}/custom-exporter:latest
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM --platform=$BUILDPLATFORM golang:1.22 AS build

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY ./main.go ./
COPY ./pkg ./pkg

ARG TARGETPLATFORM
RUN echo "Building BUILDPLATFORM: '${BUILDPLATFORM}', TARGETPLATFORM: '$TARGETPLATFORM'";
RUN GOOS=$(echo $TARGETPLATFORM | cut -d / -f1) \
GOARCH=$(echo $TARGETPLATFORM | cut -d / -f2) \
CGO_ENABLED=0 go build -ldflags="-s -w" -o ./custom-exporter .

FROM scratch
COPY --from=build /app/custom-exporter /custom-exporter
ENTRYPOINT ["/custom-exporter"]

0 comments on commit 19f76b0

Please sign in to comment.