Skip to content

Commit

Permalink
Update spot deployment and improve file handling
Browse files Browse the repository at this point in the history
This commit updates the spot deployment process and improves file handling:

1. Create a new task to set file names
2. Remove redundant file name setting in individual tasks
3. Update spot version to v1.16.4
4. Simplify spot command arguments
  • Loading branch information
umputun committed Feb 5, 2025
1 parent 6d98100 commit b9a83c9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
11 changes: 6 additions & 5 deletions publisher/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM umputun/baseimage:buildgo-latest as build
FROM umputun/baseimage:buildgo-latest AS build
ARG GIT_BRANCH
ARG GITHUB_SHA
ARG CI
Expand Down Expand Up @@ -32,10 +32,11 @@ RUN \
chmod 700 /home/app/.ssh

RUN \
wget https://github.com/umputun/spot/releases/download/v1.12.0/spot_v1.12.0_linux_amd64.apk && \
ls -la spot_v1.12.0_linux_amd64.apk && \
apk add --allow-untrusted spot_v1.12.0_linux_amd64.apk && \
rm spot_v1.12.0_linux_amd64.apk && \
export SPOT_VERSION=v1.16.4 && \
wget https://github.com/umputun/spot/releases/download/${SPOT_VERSION}/spot_${SPOT_VERSION}_linux_amd64.apk && \
ls -la spot_${SPOT_VERSION}_linux_amd64.apk && \
apk add --allow-untrusted spot_${SPOT_VERSION}_linux_amd64.apk && \
rm spot_${SPOT_VERSION}_linux_amd64.apk && \
spot --version

COPY --from=build /build/bin/publisher /usr/local/bin/publisher
Expand Down
3 changes: 1 addition & 2 deletions publisher/app/cmd/proc_mp3.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func (p *Proc) Do(mp3file string) error {
}

newsAdminCreds := fmt.Sprintf("RT_NEWS_ADMIN:%q", os.Getenv("RT_NEWS_ADMIN"))
args := []string{"-p /etc/spot.yml", "-e mp3:" + mp3file, `--task="deploy to master"`,
`--task="deploy to nodes"`, "-c 2", "-v", "-e", newsAdminCreds}
args := []string{"-p /etc/spot.yml", "-e mp3:" + mp3file, "-c 2", "-v", "-e", newsAdminCreds}
if p.Dbg {
args = append(args, "--dbg")
}
Expand Down
2 changes: 1 addition & 1 deletion publisher/app/cmd/proc_mp3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestProc_Do(t *testing.T) {
require.Equal(t, 1, len(ex.RunCalls()))
assert.Equal(t, "spot", ex.RunCalls()[0].Cmd)
assert.Equal(t, []string{"-p /etc/spot.yml", "-e mp3:/tmp/publisher_test/rt_podcast123/rt_podcast123.mp3",
"--task=\"deploy to master\"", "--task=\"deploy to nodes\"", "-c 2", "-v", "-e", `RT_NEWS_ADMIN:"test:123"`}, ex.RunCalls()[0].Params)
"-c 2", "-v", "-e", `RT_NEWS_ADMIN:"test:123"`}, ex.RunCalls()[0].Params)
}

func TestProc_setMp3Tags(t *testing.T) {
Expand Down
33 changes: 15 additions & 18 deletions publisher/spot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ targets:
# this task expects "mp3" param (full location of mp3 file) to be set by cli, i.e. -e mp3:/Podcasts/radio-t/123/rt_podcast123.mp3
tasks:

# "deploy to master" uploads mp3 to master, copy to archive, copy to local NAS, cleans old files, creates chat log and archives news
- name: deploy to master
targets: ["master"]
# set file names task sets destination file names based on episode number
- name: set file names
targets: [local]
commands:
- name: set mp3 file name
script: |
export EPISODE_NUMBER=$(echo $mp3 | sed -n 's/.*rt_podcast\(.*\)\.mp3/\1/p')
export DST_MP3_FILE_NAME=/srv/master-node/var/media/$(basename $mp3)
export DST_MP3_ARCHIVE_FILE_NAME=/data/archive/radio-t/media/$(basename $mp3)
export DST_MP3_NAS_FILE_NAME=/Volumes/Podcasts/radio-t/$(basename $mp3)
EPISODE_NUMBER=$(echo $mp3 | sed -n 's/.*rt_podcast\(.*\)\.mp3/\1/p')
DST_MP3_FILE_NAME=/srv/master-node/var/media/$(basename $mp3)
DST_MP3_ARCHIVE_FILE_NAME=/data/archive/radio-t/media/$(basename $mp3)
DST_MP3_NAS_FILE_NAME=/Podcasts/radio-t/$(basename $mp3)
options: {local: true}
register: [EPISODE_NUMBER, DST_MP3_FILE_NAME, DST_MP3_ARCHIVE_FILE_NAME, DST_MP3_NAS_FILE_NAME]

# "deploy to master" uploads mp3 to master, copy to archive, cleans old files, creates chat log and archives news
- name: deploy to master
targets: ["master"]
commands:
- name: upload mp3 file
copy: {src: "$mp3", dst: "$DST_MP3_FILE_NAME", mkdir: true}

Expand Down Expand Up @@ -49,24 +54,16 @@ tasks:
- name: deploy to nas
targets: ["nas"]
commands:
- name: set mp3 file name
script: export DST_MP3_FILE_NAME=/volume1/Podcasts/radio-t/$(basename $mp3)
- name: echo mp3 file name
echo: "$mp3 -> $DST_MP3_NAS_FILE_NAME"

- name: copy mp3 file
copy: {src: "$mp3", dst: "$DST_MP3_FILE_NAME", mkdir: true, force: true}

- name: set permissions
script: chmod 644 $DST_MP3_FILE_NAME
options: {sudo: true}
copy: {src: "$mp3", dst: "$DST_MP3_NAS_FILE_NAME", mkdir: true, force: true}

# deploy to nodes task uploads mp3 to all nodes and cleans old files
- name: deploy to nodes
targets: ["nodes"]
commands:
- name: set mp3 file name
script: export DST_MP3_FILE_NAME=/srv/media/radio-t/$(basename $mp3)
options: {local: true}

- name: copy mp3 file
copy: {src: "$mp3", dst: "$DST_MP3_FILE_NAME", mkdir: true, force: true}

Expand Down

0 comments on commit b9a83c9

Please sign in to comment.