diff --git a/.dockerignore b/.dockerignore index 26b2d6d..aa6927e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,9 @@ .dockerignore .gitignore -Dockerfile +Dockerfile-build-standalone README.md -heimdall \ No newline at end of file +heimdall +Dockerfile +.goreleaser.yaml +dist +.github \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..91da561 --- /dev/null +++ b/.github/workflows/build.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b8c5a17 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1e2a0b6..8594faf 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ go.work .idea -heimdall \ No newline at end of file +heimdall +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..a1c67fa --- /dev/null +++ b/.goreleaser.yaml @@ -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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index c2f3852..3c391a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file +ENTRYPOINT ["heimdall"] \ No newline at end of file diff --git a/Dockerfile-build-standalone b/Dockerfile-build-standalone new file mode 100644 index 0000000..c2f3852 --- /dev/null +++ b/Dockerfile-build-standalone @@ -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"] \ No newline at end of file diff --git a/heimdall b/heimdall deleted file mode 100755 index c6e36f7..0000000 Binary files a/heimdall and /dev/null differ