Skip to content

Commit

Permalink
Add nightly build job
Browse files Browse the repository at this point in the history
  • Loading branch information
mxpv committed May 5, 2023
1 parent 5adb7fb commit 748084d
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 30 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Nightly

on:
schedule:
- cron: "0 0 * * *" # Every day at midnight
push:
paths:
- ".github/workflows/nightly.yml"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
publish:
name: Nightly
runs-on: ubuntu-latest
timeout-minutes: 10

permissions:
contents: read
packages: write

steps:
- name: 📦 Checkout repository
uses: actions/checkout@v3

- name: 🧪 Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: 🔒 Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: 🏗️ Build and push
uses: docker/build-push-action@v4
with:
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly
11 changes: 0 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,3 @@ jobs:
DOCKERHUB_USER: ${{ secrets.DOCKER_LOGIN }}
GHCR_USER: ${{ env.GHCR_USER }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Publish nightly build.
- uses: goreleaser/goreleaser-action@v4.2.0
if: ${{ github.repository_owner == 'mxpv' && github.event_name == 'schedule' }}
with:
version: latest
args: release --rm-dist --nightly
env:
DOCKERHUB_USER: ${{ secrets.DOCKER_LOGIN }}
GHCR_USER: ${{ env.GHCR_USER }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27 changes: 19 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# This is a template to be used by GoReleaser.
# See docs for details: https://goreleaser.com/customization/docker/
FROM golang:1.20 as builder

FROM alpine:3.16
WORKDIR /app
WORKDIR /build

COPY . .

RUN make build

# Download youtube-dl
RUN wget -O /usr/bin/yt-dlp https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp && \
chmod +x /usr/bin/yt-dlp && \
ln -s /usr/bin/yt-dlp /usr/bin/youtube-dl && \
apk --no-cache add ca-certificates python3 py3-pip ffmpeg tzdata
COPY podsync /app/podsync
chmod +x /usr/bin/yt-dlp

FROM alpine:3.17

WORKDIR /app

RUN apk --no-cache add ca-certificates python3 py3-pip ffmpeg tzdata \
# https://github.com/golang/go/issues/59305
libc6-compat && ln -s /lib/libc.so.6 /usr/lib/libresolv.so.2

COPY --from=builder /usr/bin/yt-dlp /usr/bin/youtube-dl
COPY --from=builder /build/bin/podsync /app/podsync

ENTRYPOINT ["/app/podsync"]
CMD ["--no-banner"]
24 changes: 19 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,33 @@ all: build test

#
# Build Podsync CLI binary
# Example:
# $ GOOS=amd64 make build
#

GOARCH ?= $(shell go env GOARCH)
GOOS ?= $(shell go env GOOS)

TAG := $(shell git tag --points-at HEAD)
HASH := $(shell git rev-parse --short HEAD)
DATE := $(shell date)

LDFLAGS := "-X 'main.version=${TAG}' -X 'main.commit=${HASH}' -X 'main.date=${DATE}' -X 'main.arch=${GOARCH}'"

.PHONY: build
build:
go build -o bin/podsync ./cmd/podsync
go build -ldflags ${LDFLAGS} -o bin/podsync ./cmd/podsync

#
# Build Docker image
# Build a local Docker image
# Example:
# $ make docker
# $ docker run -it --rm localhost/podsync:latest
#
TAG ?= localhost/podsync
IMAGE_TAG ?= localhost/podsync
.PHONY: docker
docker:
docker build -t $(TAG) .
docker push $(TAG)
docker buildx build -t $(IMAGE_TAG) .

#
# Run unit tests
Expand Down
14 changes: 8 additions & 6 deletions cmd/podsync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
version = "dev"
commit = "none"
date = "unknown"
arch = ""
)

func main() {
Expand Down Expand Up @@ -75,6 +76,13 @@ func main() {
log.Info(banner)
}

log.WithFields(log.Fields{
"version": version,
"commit": commit,
"date": date,
"arch": arch,
}).Info("running podsync")

// Load TOML file
log.Debugf("loading configuration %q", opts.ConfigPath)
cfg, err := LoadConfig(opts.ConfigPath)
Expand All @@ -99,12 +107,6 @@ func main() {
}
}

log.WithFields(log.Fields{
"version": version,
"commit": commit,
"date": date,
}).Info("running podsync")

downloader, err := ytdl.New(ctx, cfg.Downloader)
if err != nil {
log.WithError(err).Fatal("youtube-dl error")
Expand Down

0 comments on commit 748084d

Please sign in to comment.