Skip to content

Commit 647945c

Browse files
authored
ci: unify local and ci docker workflows (#907)
* deps: go to 1.22.3 * removed ci dockerfile * add make buildx * updated dockerfile * ci uses make buildx command * commented upx for the future * disable openbsd/arm tests * wip * put dist file in dist path * removed unused make command * build-local to speed up local tests * don't clean when buildx * podman workaround * manually define source files for tests
1 parent a6e5570 commit 647945c

12 files changed

Lines changed: 113 additions & 50 deletions

File tree

.github/workflows/_buildx.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@ jobs:
1414
- uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # 4.1.7
1515
with:
1616
name: dist
17-
- name: Prep binaries
18-
working-directory: .github/workflows/docker
19-
run: |
20-
mkdir binaries
21-
cp -r ../../../shiori_linux_* binaries/
22-
mv binaries/shiori_linux_arm_7 binaries/shiori_linux_arm
23-
mv binaries/shiori_linux_amd64_v1 binaries/shiori_linux_amd64
24-
gzip -d -S binaries/.gz__ -r .
25-
chmod 755 binaries/shiori_linux_*/shiori
17+
path: ./dist
2618

2719
# Every pull request that goes into master
2820
- name: Prepare master push tags
@@ -55,9 +47,7 @@ jobs:
5547
echo "tag_flags=--tag $REPO:pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
5648
5749
- name: Buildx
58-
working-directory: .github/workflows/docker
5950
run: |
6051
set -x
6152
echo "${{ secrets.GITHUB_TOKEN }}" | docker login -u "${{ github.repository_owner }}" --password-stdin ghcr.io
62-
docker buildx create --use --name builder
63-
docker buildx build -f Dockerfile.ci --platform=linux/amd64,arm64,linux/arm/v7 --push ${{ env.tag_flags }} .
53+
make buildx CONTAINER_BUILDX_OPTIONS="--push ${{ env.tag_flags }}"

.github/workflows/_test.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ jobs:
107107
architecture: x86-64
108108
version: '7.5'
109109

110-
- name: openbsd
111-
architecture: arm64
112-
version: '7.5'
113110
steps:
114111
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
115112

.github/workflows/docker/Dockerfile.ci

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/docker/etc/group

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/workflows/docker/etc/passwd

Lines changed: 0 additions & 2 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ dist/
2222

2323
# frontend
2424
node_modules
25+
26+
# workaround for buildx using podman
27+
type=docker

.goreleaser.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ archives:
3636
- goos: windows
3737
format: zip
3838

39+
# TODO:
40+
# upx:
41+
# - enabled: true
42+
# ids:
43+
# - shiori
44+
# goos: [linux, darwin]
45+
# goarch: [amd64, arm, arm64]
46+
# goarm: ["7"]
47+
3948
checksum:
4049
name_template: 'checksums.txt'
4150
snapshot:

Dockerfile

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1-
# build stage
2-
FROM ghcr.io/ghcri/golang:1.21-alpine3.19 AS builder
3-
WORKDIR /src
4-
COPY . .
5-
RUN go build -ldflags '-s -w'
1+
# Build stage
2+
ARG ALPINE_VERSION
3+
ARG GOLANG_VERSION
64

7-
# server image
5+
FROM docker.io/library/alpine:${ALPINE_VERSION} AS builder
6+
ARG TARGETARCH
7+
ARG TARGETOS
8+
ARG TARGETVARIANT
9+
COPY dist/shiori_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}/shiori /usr/bin/shiori
10+
RUN apk add --no-cache ca-certificates tzdata && \
11+
chmod +x /usr/bin/shiori
12+
13+
# Server image
14+
FROM scratch
15+
16+
ENV PORT 8080
17+
ENV SHIORI_DIR=/shiori
18+
WORKDIR ${SHIORI_DIR}
19+
20+
LABEL org.opencontainers.image.source="https://github.com/go-shiori/shiori"
21+
LABEL maintainer="Felipe Martin <github@fmartingr.com>"
22+
23+
COPY --from=builder /usr/bin/shiori /usr/bin/shiori
24+
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
25+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
26+
27+
EXPOSE ${PORT}
828

9-
FROM docker.io/alpine:3.19
10-
LABEL org.opencontainers.image.source https://github.com/go-shiori/shiori
11-
COPY --from=builder /src/shiori /usr/bin/
12-
RUN addgroup -g 1000 shiori \
13-
&& adduser -D -h /shiori -g '' -G shiori -u 1000 shiori
14-
USER shiori
15-
WORKDIR /shiori
16-
EXPOSE 8080
17-
ENV SHIORI_DIR /shiori/
1829
ENTRYPOINT ["/usr/bin/shiori"]
1930
CMD ["server"]

Makefile

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
GO ?= $(shell command -v go 2> /dev/null)
22
BASH ?= $(shell command -v bash 2> /dev/null)
3+
GOLANG_VERSION := $(shell head -n 4 go.mod | tail -n 1 | cut -d " " -f 2)
34

45
# Development
56
SHIORI_DIR ?= dev-data
7+
SOURCE_FILES ?=./internal/...
68

79
# Build
810
CGO_ENABLED ?= 0
@@ -11,6 +13,16 @@ BUILD_HASH := $(shell git describe --tags)
1113
BUILD_TAGS ?= osusergo,netgo,fts5
1214
LDFLAGS += -s -w -X main.version=$(BUILD_HASH) -X main.date=$(BUILD_TIME)
1315

16+
# Build (container)
17+
CONTAINER_RUNTIME := docker
18+
CONTAINERFILE_NAME := Dockerfile
19+
CONTAINER_ALPINE_VERSION := 3.19
20+
BUILDX_PLATFORMS := linux/amd64,linux/arm64,linux/arm/v7
21+
22+
# This is used for local development only, forcing linux to create linux only images but with the arch
23+
# of the running machine. Far from perfect but works.
24+
LOCAL_BUILD_PLATFORM = linux/$(shell go env GOARCH)
25+
1426
# Testing
1527
GO_TEST_FLAGS ?= -v -race -count=1 -tags $(BUILD_TAGS) -covermode=atomic -coverprofile=coverage.out
1628
GOTESTFMT_FLAGS ?=
@@ -26,6 +38,15 @@ SWAGGER_DOCS_PATH ?= ./docs/swagger
2638
# Frontend
2739
CLEANCSS_OPTS ?= --with-rebase
2840

41+
# Common exports
42+
export GOLANG_VERSION
43+
export CONTAINER_RUNTIME
44+
export CONTAINERFILE_NAME
45+
export CONTAINER_ALPINE_VERSION
46+
export BUILDX_PLATFORMS
47+
48+
export SOURCE_FILES
49+
2950
# Help documentatin à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
3051
.PHONY: help
3152
help:
@@ -87,12 +108,29 @@ styles-check:
87108
## Build binary
88109
.PHONY: build
89110
build: clean
90-
GIN_MODE=$(GIN_MODE) goreleaser build --rm-dist --snapshot
111+
GIN_MODE=$(GIN_MODE) goreleaser build --clean --snapshot
112+
113+
## Build binary for current targer
114+
build-local: clean
115+
GIN_MODE=$(GIN_MODE) goreleaser build --clean --snapshot --single-target
116+
117+
## Build docker image using Buildx.
118+
# used for multi-arch builds suing mainly the CI, that's why the task does not
119+
# build the binaries using a dependency task.
120+
.PHONY: buildx
121+
buildx:
122+
$(info: Make: Buildx)
123+
@bash scripts/buildx.sh
124+
125+
## Build docker image for local development
126+
buildx-local: build-local
127+
$(info: Make: Build image locally)
128+
CONTAINER_BUILDX_OPTIONS="-t shiori:localdev --output type=docker" BUILDX_PLATFORMS=$(LOCAL_BUILD_PLATFORM) scripts/buildx.sh
91129

92130
## Creates a coverage report
93131
.PHONY: coverage
94132
coverage:
95-
$(GO) test $(GO_TEST_FLAGS) -coverprofile=coverage.txt ./...
133+
$(GO) test $(GO_TEST_FLAGS) -coverprofile=coverage.txt $(SOURCE_FILES)
96134
$(GO) tool cover -html=coverage.txt
97135

98136
## Run generate accross the project

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module github.com/go-shiori/shiori
22

33
// +heroku goVersion go1.22
4-
go 1.22.2
4+
go 1.22.3
55

66
require (
77
git.sr.ht/~emersion/go-sqlite3-fts5 v0.0.0-20230217131031-f2c8767594fc

0 commit comments

Comments
 (0)