Skip to content

Commit

Permalink
ci: add build files
Browse files Browse the repository at this point in the history
  • Loading branch information
EverythingSuckz committed Nov 29, 2023
1 parent c0f9000 commit 1b1f2d9
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 1 deletion.
49 changes: 49 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Package Build

on:
workflow_dispatch:
push:
tags:
- '*'
env:
DOCKER_BUILDKIT: 1

jobs:
build_image:
name: Build Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config-inline: |
[worker.oci]
platforms = ["linux/amd64", "linux/arm64"]
max-parallelism = 4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Setup ENV vars
id: env-vars
run: |
echo "TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo "IMAGE_NAME=ghcr.io/${GITHUB_ACTOR}/fsb" >> $GITHUB_ENV
- name: Build docker image and push
uses: docker/build-push-action@v5
with:
context: ./
pull: true
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ env.IMAGE_NAME }}:${{ env.TAG }} , ${{ env.IMAGE_NAME }}:latest
51 changes: 50 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ builds:
goarch:
- amd64
- arm64
mod_timestamp: '{{ .CommitTimestamp }}'

archives:
- format: tar.gz
Expand Down Expand Up @@ -49,4 +50,52 @@ changelog:
filters:
exclude:
- "^docs:"
- "^test:"
- "^test:"

dockers:
# amd64 only
- goarch: amd64
dockerfile: goreleaser.Dockerfile
use: buildx
image_templates:
- "ghcr.io/EverythingSuckz/{{ .ProjectName }}:{{ .Tag }}-amd64"
build_flag_templates:
- "--platform=linux/amd64"
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
# arm64 only
- goarch: arm64
dockerfile: goreleaser.Dockerfile
use: buildx
image_templates:
- "ghcr.io/EverythingSuckz/{{ .ProjectName }}:{{ .Tag }}-amd64"
build_flag_templates:
- "--platform=linux/arm64/v8"
- "--pull"
- "--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: "ghcr.io/EverythingSuckz/{{ .ProjectName }}:{{ .Version }}"
image_templates:
- "ghcr.io/EverythingSuckz/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "ghcr.io/EverythingSuckz/{{ .ProjectName }}:{{ .Tag }}-arm64v8"
- name_template: "ghcr.io/EverythingSuckz/{{ .ProjectName }}:latest"
image_templates:
- "ghcr.io/EverythingSuckz/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "ghcr.io/EverythingSuckz/{{ .ProjectName }}:{{ .Tag }}-arm64v8"

# github container registry
- name_template: "ghcr.io/EverythingSuckz/{{ .ProjectName }}:{{ .Version }}"
image_templates:
- "ghcr.io/EverythingSuckz/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "ghcr.io/EverythingSuckz/{{ .ProjectName }}:{{ .Tag }}-arm64v8"
- name_template: "ghcr.io/EverythingSuckz/{{ .ProjectName }}:latest"
image_templates:
- "ghcr.io/EverythingSuckz/{{ .ProjectName }}:{{ .Tag }}-amd64"
- "ghcr.io/EverythingSuckz/{{ .ProjectName }}:{{ .Tag }}-arm64v8"
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:1.21 AS builder
RUN apt-get update && apt-get upgrade -y && apt-get install build-essential -y
WORKDIR /app
COPY . .
RUN CGO_ENABLED=1 GOOS=`go env GOHOSTOS` GOARCH=`go env GOHOSTARCH` go build ./cmd/fsb/ -o out/fsb -ldflags="-w -s" .

FROM golang:1.21
COPY --from=builder /app/out/fsb /app/fsb
CMD ["/app/fsb"]
14 changes: 14 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3.9"

services:
fsb:
build:
context: .
dockerfile: Dockerfile
restart: always
container_name: fsb
volumes:
- ./:/app/:rw
env_file: fsb.env
ports:
- 8080:8080
2 changes: 2 additions & 0 deletions goreleaser.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM golang:1.21
CMD ["/app/fsb"]

0 comments on commit 1b1f2d9

Please sign in to comment.