forked from go-shiori/shiori
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup new CI/CD workflows (go-shiori#365)
* CI/CD setup * Setup for go-shiori * Fix docker image * Dockerfile adjustments
- Loading branch information
Showing
15 changed files
with
281 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
docs | ||
Dockerfile | ||
*.md | ||
.githooks | ||
.github | ||
.goreleaser.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: 'Build Docker' | ||
|
||
on: workflow_call | ||
jobs: | ||
buildx: | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
name: Build Docker | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/download-artifact@v2 | ||
with: | ||
name: dist | ||
- name: Prep binaries | ||
working-directory: .github/workflows/docker | ||
run: | | ||
mkdir binaries | ||
cp -r ../../../shiori_linux_* binaries/ | ||
mv binaries/shiori_linux_arm_7 binaries/shiori_linux_arm | ||
gzip -d -S binaries/.gz__ -r . | ||
chmod 755 binaries/shiori_linux_*/shiori | ||
- name: Buildx | ||
working-directory: .github/workflows/docker | ||
run: | | ||
echo ${{ secrets.GITHUB_TOKEN }} | docker login -u go-shiori --password-stdin ghcr.io | ||
REPO=ghcr.io/go-shiori/shiori | ||
TAG=$(git describe --tags) | ||
if [ -z "$(git tag --points-at HEAD)" ] | ||
then | ||
TAG2="dev" | ||
else | ||
TAG2="latest" | ||
fi | ||
docker buildx create --use --name builder | ||
docker buildx build -f Dockerfile.ci --platform=linux/amd64,arm64,linux/arm/v7 --push --output=type=registry --tag $REPO:$TAG --tag $REPO:$TAG2 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: 'golangci-lint' | ||
|
||
on: workflow_call | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: read | ||
jobs: | ||
golangci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v2 | ||
with: | ||
version: latest | ||
|
||
# Optional: working directory, useful for monorepos | ||
# working-directory: somedir | ||
|
||
# Optional: golangci-lint command line arguments. | ||
# args: --issues-exit-code=0 | ||
|
||
# Optional: show only new issues if it's a pull request. The default value is `false`. | ||
only-new-issues: true | ||
|
||
# Optional: if set to true then the action will use pre-installed Go. | ||
# skip-go-installation: true | ||
|
||
# Optional: if set to true then the action don't cache or restore ~/go/pkg. | ||
# skip-pkg-cache: true | ||
|
||
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build. | ||
# skip-build-cache: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: 'Goreleaser' | ||
|
||
on: workflow_call | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.17 | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
distribution: goreleaser | ||
version: latest | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: dist | ||
path: ./dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: 'Unit Tests' | ||
|
||
on: workflow_call | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
go: [1.17] | ||
name: Go ${{ matrix.go }} unit tests | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
- uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/.cache/go-build | ||
~/go/pkg | ||
key: golangci-lint.cache-{platform-arch}-{interval_number}-{go.mod_hash} | ||
restore-keys: | | ||
golangci-lint.cache-{interval_number}- | ||
golangci-lint.cache- | ||
- run: go test ./... | ||
- run: CGO_ENABLED=0 go build -tags osusergo,netgo -ldflags="-s -w -X main.version=$(git describe --tags) -X main.date=$(date --iso-8601=seconds)" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM ghcr.io/ghcri/alpine:3.15 | ||
ARG TARGETARCH | ||
LABEL org.opencontainers.image.source https://github.com/go-shiori/shiori | ||
COPY etc /etc | ||
COPY binaries/shiori_linux_$TARGETARCH/shiori /usr/bin/shiori | ||
USER shiori | ||
WORKDIR /shiori | ||
EXPOSE 8080 | ||
ENV SHIORI_DIR=/shiori | ||
ENTRYPOINT ["/usr/bin/shiori"] | ||
CMD ["serve"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
root:x:0:root | ||
shiori:x:1000:shiori |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
root:x:0:0::/root:/bin/ash | ||
shiori:x:1000:1000::/shiori:/bin/ash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: 'Pull Request' | ||
|
||
on: | ||
pull_request: | ||
branches: master | ||
|
||
concurrency: | ||
group: ci-tests-${{ github.ref }}-1 | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
call-lint: | ||
uses: ./.github/workflows/_golangci-lint.yml | ||
call-test: | ||
uses: ./.github/workflows/_test.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: 'Push' | ||
|
||
on: | ||
push: | ||
branches: master | ||
tags: v* | ||
|
||
concurrency: | ||
group: ci-tests-${{ github.ref }}-1 | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
call-lint: | ||
uses: ./.github/workflows/_golangci-lint.yml | ||
call-test: | ||
uses: ./.github/workflows/_test.yml | ||
call-gorelease: | ||
uses: ./.github/workflows/_gorelease.yml | ||
call-buildx: | ||
needs: call-gorelease | ||
uses: ./.github/workflows/_buildx.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: 'Tag release' | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: 'Version to bump to, example: v1.5.2' | ||
required: true | ||
|
||
jobs: | ||
tag-release: | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
ref: master | ||
- name: Tag release | ||
run: | | ||
git config user.email "[email protected]" | ||
git config user.name "shiori" | ||
git tag -a ${{ github.event.inputs.version }} -m "tag release ${{ github.event.inputs.version }}" | ||
git push --follow-tags | ||
call-gorelease: | ||
needs: tag-release | ||
uses: ./.github/workflows/_gorelease.yml | ||
call-buildx: | ||
needs: call-gorelease | ||
uses: ./.github/workflows/_buildx.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ | |
|
||
# Coverage data | ||
/coverage.out | ||
|
||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
before: | ||
hooks: | ||
- go mod tidy | ||
builds: | ||
- binary: shiori | ||
env: | ||
- CGO_ENABLED=0 | ||
tags: | ||
- netgo | ||
- osusergo | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
goarch: | ||
- amd64 | ||
- arm | ||
- arm64 | ||
goarm: | ||
- 7 | ||
ignore: | ||
- goos: darwin | ||
goarch: arm | ||
- goos: windows | ||
goarch: arm | ||
- goos: windows | ||
goarch: arm64 | ||
archives: | ||
- replacements: | ||
darwin: Darwin | ||
linux: Linux | ||
windows: Windows | ||
amd64: x86_64 | ||
arm64: aarch64 | ||
|
||
checksum: | ||
name_template: 'checksums.txt' | ||
snapshot: | ||
name_template: "{{ incpatch .Version }}-next" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' | ||
|
||
release: | ||
prerelease: auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
# build stage | ||
FROM ghcr.io/ghcri/golang:1.17-alpine3.15 AS builder | ||
RUN apk add --no-cache build-base | ||
WORKDIR /src | ||
COPY . . | ||
RUN go build | ||
RUN go build -ldflags '-s -w' | ||
|
||
# server image | ||
LABEL org.opencontainers.image.source https://github.com/go-shiori/shiori | ||
|
||
FROM ghcr.io/ghcri/alpine:3.15 | ||
COPY --from=builder /src/shiori /usr/local/bin/ | ||
ENV SHIORI_DIR /srv/shiori/ | ||
LABEL org.opencontainers.image.source https://github.com/go-shiori/shiori | ||
COPY --from=builder /src/shiori /usr/bin/ | ||
RUN addgroup -g 1000 shiori \ | ||
&& adduser -D -h /shiori -g '' -G shiori -u 1000 shiori | ||
USER shiori | ||
WORKDIR /shiori | ||
EXPOSE 8080 | ||
ENTRYPOINT ["/usr/local/bin/shiori"] | ||
ENV SHIORI_DIR /shiori/ | ||
ENTRYPOINT ["/usr/bin/shiori"] | ||
CMD ["serve"] |