diff --git a/.dockerignore b/.dockerignore index c6b56acf1..445e23cb7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,5 @@ .DS_Store ui/node_modules -ui/build Jamstash-master Dockerfile docker-compose*.yml diff --git a/.github/workflows/Dockerfile.pipeline b/.github/workflows/Dockerfile.pipeline new file mode 100644 index 000000000..40ac80153 --- /dev/null +++ b/.github/workflows/Dockerfile.pipeline @@ -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"] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2cf9cc51d..b32e8c5ee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -97,7 +97,6 @@ jobs: - name: Run GoReleaser uses: docker://deluan/ci-goreleaser:1.14.1-1 - env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: diff --git a/.github/workflows/docker-tags.sh b/.github/workflows/docker-tags.sh new file mode 100755 index 000000000..5a43b1fb9 --- /dev/null +++ b/.github/workflows/docker-tags.sh @@ -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} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d21c60a7..1a4bd0da2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 . diff --git a/.goreleaser.yml b/.goreleaser.yml index f763f35ac..47ac03580 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -143,7 +143,7 @@ release: draft: true changelog: - sort: asc + # sort: asc filters: exclude: - "^docs:"