Skip to content

Commit

Permalink
Merge pull request #6 from RobinHeidenis/feat/add-pipeline
Browse files Browse the repository at this point in the history
feat: 🎸 add pipeline
  • Loading branch information
RobinHeidenis authored Nov 29, 2023
2 parents 1d8b959 + 6facafa commit b0d855d
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 24 deletions.
8 changes: 6 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.dockerignore
.gitignore
Dockerfile
Dockerfile-build-standalone
README.md
heimdall
heimdall
Dockerfile
.goreleaser.yaml
dist
.github
44 changes: 44 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build
run-name: Build heimdall for ${{ github.actor }} on ${{ github.base.ref }}
on:
push:
branches-ignore:
- main
workflow_call:
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.21.4
- name: Install dependencies
run: go mod download

- name: Build heimdall for linux/amd64
run: GOOS=linux GOARCH=amd64 go build -o dist/heimdall-linux-amd64 ./cmd/heimdall
- name: Upload heimdall for linux/amd64
uses: actions/upload-artifact@v3
with:
name: heimdall-linux-amd64
path: dist/heimdall-linux-amd64

- name: Build heimdall for linux/arm64
run: GOOS=linux GOARCH=arm64 go build -o dist/heimdall-linux-arm64 ./cmd/heimdall
- name: Upload heimdall for linux/arm64
uses: actions/upload-artifact@v3
with:
name: heimdall-linux-arm64
path: dist/heimdall-linux-arm64

- name: Build heimdall for linux/arm
run: GOOS=linux GOARCH=arm go build -o dist/heimdall-linux-arm ./cmd/heimdall
- name: Upload heimdall for linux/arm
uses: actions/upload-artifact@v3
with:
name: heimdall-linux-arm
path: dist/heimdall-linux-arm
40 changes: 40 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Release
run-name: Release heimdall
on:
push:
tags:
- "*"

permissions:
contents: write
packages: write

jobs:
goreleaser:
name: Build and Release Heimdall binaries and container images
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: stable
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ go.work

.idea

heimdall
heimdall
dist/
146 changes: 146 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 1

project_name: heimdall

report_sizes: true

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
-
main: ./cmd/heimdall
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
- arm
goarm:
- 6
- 7

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

dockers:
- use: buildx
goos: linux
goarch: amd64
image_templates:
- "drfractum/{{ .ProjectName }}:{{ .Version }}-amd64"
- "drfractum/{{ .ProjectName }}:{{ .Major }}-amd64"
- "drfractum/{{ .ProjectName }}:{{ .Major }}.{{ .Minor }}-amd64"
- "drfractum/[{ .ProjectName }}:latest-amd64"
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- use: buildx
goos: linux
goarch: arm64
image_templates:
- "drfractum/{{ .ProjectName }}:{{ .Version }}-arm64v8"
- "drfractum/{{ .ProjectName }}:{{ .Major }}-arm64v8"
- "drfractum/{{ .ProjectName }}:{{ .Major }}.{{ .Minor }}-arm64v8"
- "drfractum/[{ .ProjectName }}:latest-arm64v8"
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/arm64/v8"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- use: buildx
goos: linux
goarch: arm
image_templates:
- "drfractum/{{ .ProjectName }}:{{ .Version }}-armv6"
- "drfractum/{{ .ProjectName }}:{{ .Major }}-armv6"
- "drfractum/{{ .ProjectName }}:{{ .Major }}.{{ .Minor }}-armv6"
- "drfractum/[{ .ProjectName }}:latest-armv6"
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/arm/v6"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- use: buildx
goos: linux
goarch: arm
goarm: 7
image_templates:
- "drfractum/{{ .ProjectName }}:{{ .Version }}-armv7"
- "drfractum/{{ .ProjectName }}:{{ .Major }}-armv7"
- "drfractum/{{ .ProjectName }}:{{ .Major }}.{{ .Minor }}-armv7"
- "drfractum/[{ .ProjectName }}:latest-armv7"
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/arm/v7"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"

docker_manifests:
- name_template: "drfractum/{{ .ProjectName }}:{{ .Version }}"
image_templates:
- "drfractum/{{ .ProjectName }}:{{ .Version }}-amd64"
- "drfractum/{{ .ProjectName }}:{{ .Version }}-arm64v8"
- "drfractum/{{ .ProjectName }}:{{ .Version }}-armv6"
- "drfractum/{{ .ProjectName }}:{{ .Version }}-armv7"
- name_template: "drfractum/{{ .ProjectName }}:latest"
image_templates:
- "drfractum/{{ .ProjectName }}:latest-amd64"
- "drfractum/{{ .ProjectName }}:latest-arm64v8"
- "drfractum/{{ .ProjectName }}:latest-armv6"
- "drfractum/{{ .ProjectName }}:latest-armv7"

checksum:
name_template: 'checksums.txt'

source:
enabled: true

announce:
discord:
enabled: true
24 changes: 3 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
FROM golang:latest as BUILD
LABEL authors="Robin Heidenis"

WORKDIR /app

# Download dependencies
COPY go.mod go.sum ./
RUN go mod download

# Copy source code
COPY . .

# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -o /heimdall ./cmd/heimdall

FROM alpine:latest
LABEL authors="Robin Heidenis"

WORKDIR /

COPY --from=BUILD /heimdall /heimdall
COPY heimdall heimdall

# Expose port 8080 for healthchecks
EXPOSE 8080

HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD wget localhost:8080/health -q -O - > /dev/null 2>&1

VOLUME /var/run/docker.sock

# Run the application
CMD ["/heimdall"]
ENTRYPOINT ["heimdall"]
30 changes: 30 additions & 0 deletions Dockerfile-build-standalone
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM golang:latest as BUILD
LABEL authors="Robin Heidenis"

WORKDIR /app

# Download dependencies
COPY go.mod go.sum ./
RUN go mod download

# Copy source code
COPY . .

# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -o /heimdall ./cmd/heimdall

FROM alpine:latest

WORKDIR /

COPY --from=BUILD /heimdall /heimdall

# Expose port 8080 for healthchecks
EXPOSE 8080

HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD wget localhost:8080/health -q -O - > /dev/null 2>&1

VOLUME /var/run/docker.sock

# Run the application
CMD ["/heimdall"]
Binary file removed heimdall
Binary file not shown.

0 comments on commit b0d855d

Please sign in to comment.