From 1b1f2d908541ce5d69363bc919860e33d8d62211 Mon Sep 17 00:00:00 2001 From: wrench Date: Thu, 30 Nov 2023 01:37:25 +0530 Subject: [PATCH] ci: add build files --- .github/workflows/build.yml | 49 +++++++++++++++++++++++++++++++++++ .goreleaser.yaml | 51 ++++++++++++++++++++++++++++++++++++- Dockerfile | 9 +++++++ docker-compose.yaml | 14 ++++++++++ goreleaser.Dockerfile | 2 ++ 5 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yaml create mode 100644 goreleaser.Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..f08a47cc --- /dev/null +++ b/.github/workflows/build.yml @@ -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 \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml index dc0c274d..e8e11e0c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -21,6 +21,7 @@ builds: goarch: - amd64 - arm64 + mod_timestamp: '{{ .CommitTimestamp }}' archives: - format: tar.gz @@ -49,4 +50,52 @@ changelog: filters: exclude: - "^docs:" - - "^test:" \ No newline at end of file + - "^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" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..8442a2d0 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..3df551be --- /dev/null +++ b/docker-compose.yaml @@ -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 \ No newline at end of file diff --git a/goreleaser.Dockerfile b/goreleaser.Dockerfile new file mode 100644 index 00000000..ec1d21f4 --- /dev/null +++ b/goreleaser.Dockerfile @@ -0,0 +1,2 @@ +FROM golang:1.21 +CMD ["/app/fsb"] \ No newline at end of file