diff --git a/.dockerignore b/.dockerignore index 445e23cb..9bf6d78f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -10,4 +10,4 @@ navidrome navidrome.db navidrome.toml assets/*gen.go -dist + diff --git a/.github/workflows/Dockerfile.pipeline b/.github/workflows/Dockerfile.pipeline deleted file mode 100644 index 40ac8015..00000000 --- a/.github/workflows/Dockerfile.pipeline +++ /dev/null @@ -1,51 +0,0 @@ -##################################################### -### 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 deleted file mode 100644 index b32e8c5e..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,108 +0,0 @@ -name: Build -on: - push: - pull_request: - types: [closed] - branches: - - master -jobs: - go: - name: Test Server on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - matrix: - # TODO Fix tests in Windows - # os: [macOS-latest, ubuntu-latest, windows-latest] - os: [macOS-latest, ubuntu-latest] - - steps: - - name: Set up Go 1.14 - uses: actions/setup-go@v1 - with: - go-version: 1.14 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - uses: actions/cache@v1 - id: cache-go - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: Download dependencies - if: steps.cache-go.outputs.cache-hit != 'true' - run: go mod download - - - name: Test - run: go test -cover ./... -v - - js: - name: Test UI - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - with: - node-version: 13 - - - 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 - - # TODO: Enable when there are tests to run - # - name: npm test - # run: | - # cd ui - # CI=test npm test - - - name: npm build - run: | - cd ui - npm run build - - - uses: actions/upload-artifact@v1 - with: - name: js-bundle - path: ui/build - - build: - name: Build snapshot binaries - if: github.event.pull_request.merged || github.event_name == 'push' - 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 --skip-publish --snapshot - - - uses: actions/upload-artifact@v1 - with: - name: binaries - path: dist diff --git a/.github/workflows/pipeline.dockerfile b/.github/workflows/pipeline.dockerfile new file mode 100644 index 00000000..d67e54fe --- /dev/null +++ b/.github/workflows/pipeline.dockerfile @@ -0,0 +1,40 @@ +##################################################### +### Copy platform specific binary +FROM bash as copy-binary +ARG TARGETPLATFORM + +RUN echo "Target Platform = ${TARGETPLATFORM}" + +COPY dist . +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then cp navidrome_linux_musl_amd64_linux_amd64/navidrome /navidrome; fi +RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then cp navidrome_linux_arm64_linux_arm64/navidrome /navidrome; fi +RUN if [ "$TARGETPLATFORM" = "linux/arm/v6" ]; then cp navidrome_linux_arm_linux_arm_6/navidrome /navidrome; fi +RUN if [ "$TARGETPLATFORM" = "linux/arm/v7" ]; then cp navidrome_linux_arm_linux_arm_7/navidrome /navidrome; fi + + +##################################################### +### Build Final Image +FROM alpine as release +LABEL maintainer="deluan@navidrome.org" + +# Install ffmpeg and output build config +RUN apk add --no-cache ffmpeg +RUN ffmpeg -buildconf + +COPY --from=copy-binary /navidrome /app/ +RUN chmod +x /app/navidrome + +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/release.yml b/.github/workflows/release.yml index 1a4bd0da..5184f852 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,14 +1,41 @@ name: Release -on: - push: - branches: - - master - tags: - - "v*" +on: push jobs: + go: + name: Test Server on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + # TODO Fix tests in Windows + # os: [macOS-latest, ubuntu-latest, windows-latest] + os: [macOS-latest, ubuntu-latest] + + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - uses: actions/cache@v1 + id: cache-go + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + if: steps.cache-go.outputs.cache-hit != 'true' + run: go mod download + + - name: Test + run: go test -cover ./... -v js: name: Build JS bundle - if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master' runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -41,8 +68,7 @@ jobs: binaries: name: Binaries - if: startsWith(github.ref, 'refs/tags/') - needs: [js] + needs: [js, go] runs-on: ubuntu-latest steps: - name: Checkout Code @@ -56,17 +82,30 @@ jobs: name: js-bundle path: ui/build - - name: Run GoReleaser + - name: Run GoReleaser - SNAPSHOT + if: startsWith(github.ref, 'refs/tags/') != true + uses: docker://deluan/ci-goreleaser:1.14.1-1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: goreleaser release --rm-dist --skip-publish --snapshot + + - name: Run GoReleaser - RELEASE + if: startsWith(github.ref, 'refs/tags/') uses: docker://deluan/ci-goreleaser:1.14.1-1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: args: goreleaser release --rm-dist + - uses: actions/upload-artifact@v1 + with: + name: binaries + path: dist + docker: name: Docker images - if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master' - needs: [js] + needs: [binaries] runs-on: ubuntu-latest steps: - name: Set up Docker Buildx @@ -79,8 +118,8 @@ jobs: - uses: actions/download-artifact@v1 with: - name: js-bundle - path: ui/build + name: binaries + path: dist - name: Build the Docker image and push env: @@ -88,4 +127,4 @@ jobs: 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 . + docker buildx build --platform ${DOCKER_PLATFORM} `.github/workflows/docker-tags.sh` -f .github/workflows/pipeline.dockerfile --push . diff --git a/.goreleaser.yml b/.goreleaser.yml index 47ac0358..0f076a26 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,4 +1,5 @@ # GoReleaser config +project_name: navidrome before: hooks: