Build and release docker images

This commit is contained in:
Deluan 2020-04-17 13:52:18 -04:00 committed by Deluan Quintão
parent eaa48306fc
commit f7b3ff4b34
6 changed files with 138 additions and 15 deletions

View File

@ -1,6 +1,5 @@
.DS_Store
ui/node_modules
ui/build
Jamstash-master
Dockerfile
docker-compose*.yml

51
.github/workflows/Dockerfile.pipeline vendored Normal file
View File

@ -0,0 +1,51 @@
#####################################################
### Build executable
FROM golang:1.14-alpine AS gobuilder
# Download build tools
RUN mkdir -p /src/ui/build
RUN apk add -U --no-cache build-base git
RUN go get -u github.com/go-bindata/go-bindata/...
# Download project dependencies
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
# Copy source, test it
COPY . .
RUN go test ./...
# Copy UI bundle, build executable
RUN GIT_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) && \
GIT_TAG=${GIT_TAG#"tags/"} && \
GIT_SHA=$(git rev-parse --short HEAD) && \
echo "Building version: ${GIT_TAG} (${GIT_SHA})" && \
go-bindata -fs -prefix ui/build -tags embed -nocompress -pkg assets -o assets/embedded_gen.go ui/build/... && \
go build -ldflags="-X github.com/deluan/navidrome/consts.gitSha=${GIT_SHA} -X github.com/deluan/navidrome/consts.gitTag=${GIT_TAG}" -tags=embed
#####################################################
### Build Final Image
FROM alpine as release
LABEL maintainer="deluan@navidrome.org"
COPY --from=gobuilder /src/navidrome /app/
# Install ffmpeg and output build config
RUN apk add --no-cache ffmpeg
RUN ffmpeg -buildconf
VOLUME ["/data", "/music"]
ENV ND_MUSICFOLDER /music
ENV ND_DATAFOLDER /data
ENV ND_SCANINTERVAL 1m
ENV ND_TRANSCODINGCACHESIZE 100MB
ENV ND_SESSIONTIMEOUT 30m
ENV ND_LOGLEVEL info
ENV ND_PORT 4533
EXPOSE ${ND_PORT}
HEALTHCHECK CMD wget -O- http://localhost:${ND_PORT}/ping || exit 1
WORKDIR /app
ENTRYPOINT ["/app/navidrome"]

View File

@ -97,7 +97,6 @@ jobs:
- name: Run GoReleaser
uses: docker://deluan/ci-goreleaser:1.14.1-1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:

17
.github/workflows/docker-tags.sh vendored Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
GIT_TAG="${GITHUB_REF##refs/tags/}"
GIT_BRANCH="${GITHUB_REF##refs/heads/}"
GIT_SHA=$(git rev-parse --short HEAD)
DOCKER_IMAGE_TAG="--tag ${DOCKER_IMAGE}:sha-${GIT_SHA}"
if [[ $GITHUB_REF != $GIT_TAG ]]; then
DOCKER_IMAGE_TAG="${DOCKER_IMAGE_TAG} --tag ${DOCKER_IMAGE}:${GIT_TAG#v} --tag ${DOCKER_IMAGE}:latest"
elif [[ $GITHUB_REF == "refs/heads/master" ]]; then
DOCKER_IMAGE_TAG="${DOCKER_IMAGE_TAG} --tag ${DOCKER_IMAGE}:develop"
elif [[ $GIT_BRANCH = feature/* ]]; then
DOCKER_IMAGE_TAG="${DOCKER_IMAGE_TAG} --tag ${DOCKER_IMAGE}:$(echo $GIT_BRANCH | tr / -)"
fi
echo ${DOCKER_IMAGE_TAG}

View File

@ -1,34 +1,91 @@
name: Release
on:
push:
branches:
- master
tags:
- "*"
- "v*"
jobs:
release:
name: Release
js:
name: Build JS bundle
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Unshallow
run: git fetch --prune --unshallow
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 13
- name: Build UI
- uses: actions/cache@v1
id: cache-npm
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('ui/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: npm install dependencies
run: |
cd ui
npm ci
- name: npm build
run: |
cd ui
npm run build
- uses: actions/upload-artifact@v1
with:
name: js-bundle
path: ui/build
binaries:
name: Binaries
if: startsWith(github.ref, 'refs/tags/')
needs: [js]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Unshallow
run: git fetch --prune --unshallow
- uses: actions/download-artifact@v1
with:
name: js-bundle
path: ui/build
- name: Run GoReleaser
uses: docker://deluan/ci-goreleaser:1.14.1-1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: goreleaser release --rm-dist
docker:
name: Docker images
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master'
needs: [js]
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest
- uses: actions/checkout@v1
- uses: actions/download-artifact@v1
with:
name: js-bundle
path: ui/build
- name: Build the Docker image and push
env:
DOCKER_IMAGE: deluan/deluan
DOCKER_PLATFORM: linux/amd64,linux/arm/v7,linux/arm64
run: |
echo ${{secrets.DOCKER_PASSWORD}} | docker login -u ${{secrets.DOCKER_USERNAME}} --password-stdin
docker buildx build --platform ${DOCKER_PLATFORM} `.github/workflows/docker-tags.sh` -f .github/workflows/Dockerfile.pipeline --push .

View File

@ -143,7 +143,7 @@ release:
draft: true
changelog:
sort: asc
# sort: asc
filters:
exclude:
- "^docs:"