Skip to content

Commit

Permalink
Merge pull request #424 from nlevee/fix/platform-docker-images
Browse files Browse the repository at this point in the history
fix(ci): build docker and binaries
  • Loading branch information
nlevee authored Nov 23, 2023
2 parents 7c0384e + c420442 commit 3437fbf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 31 deletions.
29 changes: 20 additions & 9 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Create and publish Container images

on:
pull_request:
branches:
- "main"
push:
tags:
- v*
Expand Down Expand Up @@ -61,9 +58,8 @@ jobs:
*.cache-from=type=gha
*.cache-to=type=gha,mode=max
gh-release:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
build-binaries-linux:
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
Expand All @@ -73,12 +69,12 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Create artifacts for all platform
- name: Create artifacts
uses: docker/bake-action@v4
with:
files: |
./docker-bake.hcl
targets: artifact-all
targets: artifact-linux
provenance: false

- name: Flatten artifact
Expand All @@ -92,15 +88,30 @@ jobs:
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: binaries-linux
path: release/*
if-no-files-found: error

gh-release:
needs:
- build-binaries-linux
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- uses: actions/download-artifact@v3
id: binaries

- name: Display structure of downloaded files
run: ls -R ${{steps.binaries.outputs.download-path}}

- name: GitHub Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
fail_on_unmatched_files: true
files: |
release/*
${{steps.binaries.outputs.download-path}}/binaries-linux/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 7 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1

FROM --platform=$BUILDPLATFORM docker.io/alpine:3.18 as base
FROM docker.io/alpine:3.18 as base

# Build the web ui from source
FROM --platform=$BUILDPLATFORM docker.io/node:18 AS build-node
Expand All @@ -10,27 +10,23 @@ ADD Makefile /exa/
RUN make web

# Build the application from source
FROM --platform=$BUILDPLATFORM docker.io/golang:1.21-alpine3.18 AS build-go
FROM docker.io/golang:1.21-bookworm AS build-go

ARG TARGETOS
ARG TARGETARCH
ARG TARGETOS TARGETARCH

WORKDIR /exa

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

COPY . ./
COPY --from=build-node /exa/internal/web/build /exa/internal/web/build
RUN apk add --no-cache make gcc g++ && \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} make app
COPY --link --from=build-node /exa/internal/web/build /exa/internal/web/build
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} make app

# Artifact Target
FROM scratch as artifact

ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
ARG TARGETOS TARGETARCH TARGETVARIANT

COPY --link --from=build-go /exa/build/exatorrent /exatorrent-${TARGETOS}-${TARGETARCH}${TARGETVARIANT}

Expand All @@ -57,7 +53,7 @@ LABEL org.label-schema.description="self-hostable torrent client"
LABEL org.label-schema.url="https://github.com/varbhat/exatorrent"
LABEL org.label-schema.vcs-url="https://github.com/varbhat/exatorrent"

COPY --from=build-go --chown=1000:1000 /exa/build/exatorrent /exatorrent
COPY --link --from=build-go --chown=1000:1000 /exa/build/exatorrent /exatorrent

RUN apk add -U --upgrade --no-cache \
ca-certificates
Expand Down
23 changes: 12 additions & 11 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
target "docker-metadata-action" {}
target "docker-metadata-action" {
tags = ["exatorrent:local"]
}

target "_common" {
target "default" {
inherits = ["docker-metadata-action"]
platforms = [
"darwin/amd64",
"darwin/arm64",
"linux/amd64",
"linux/arm64",
"linux/arm/v7",
"linux/ppc64le",
]
}

target "default" {
inherits = ["_common"]
}

target "artifact" {
inherits = ["docker-metadata-action"]
target = "artifact"
output = ["type=local,dest=./artifact"]
}

target "artifact-all" {
inherits = ["_common", "artifact"]
target "artifact-linux" {
inherits = ["artifact"]
platforms = [
"linux/amd64",
"linux/arm64",
"linux/arm/v7",
"linux/ppc64le",
]
}

target "release" {
Expand Down

0 comments on commit 3437fbf

Please sign in to comment.