Skip to content

Commit

Permalink
switch release to goreleaser, add deb and rpm #2
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Jul 26, 2020
1 parent c727dd1 commit 815d505
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
dist/
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@

# Dependency directories (remove the comment below to include it)
# vendor/
bin/
bin/
dist/
54 changes: 54 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
- freebsd
goarch:
- amd64
- arm
- arm64
ignore:
- goos: freebsd
goarch: arm
- goos: freebsd
goarch: arm64
dir: app
ldflags: "-s -w -X main.revision={{.Version}}-{{.CommitDate}}"

archives:
- name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
replacements:
386: i386
amd64: x86_64
darwin: macos
format_overrides:
- goos: windows
format: zip
files:
- LICENSE
- README.md

nfpms:
-
package_name: cronn
file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
vendor: Umputun
homepage: https://github.com/umputun/cronn
maintainer: Umputun <umputun@gmail.com>
description: cron replacement with extras
license: MIT
formats:
- deb
- rpm
bindir: /usr/bin
epoch: 1
release: 1
files:
"cronn.service": "/etc/systemd/system/cronn.service"
"crontab.example": "/etc/cronntab"
scripts:
postinstall: "scripts/postinstall.sh"
preremove: "scripts/preremove.sh"
32 changes: 9 additions & 23 deletions Dockerfile.artifacts
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
FROM umputun/baseimage:buildgo-latest as build
FROM goreleaser/goreleaser as build

WORKDIR /build
ADD . /build

RUN \
version=$(/script/git-rev.sh); \
echo "version=$version" && \
export GOFLAGS="-mod=vendor" && \
echo "linux-amd64" && GOOS=linux GOARCH=amd64 go build -o cronn.linux-amd64 -ldflags "-X main.revision=${version} -s -w" ./app && \
echo "linux-386" && GOOS=linux GOARCH=386 go build -o cronn.linux-386 -ldflags "-X main.revision=${version} -s -w" ./app && \
echo "linux-arm" && GOOS=linux GOARCH=arm go build -o cronn.linux-arm -ldflags "-X main.revision=${version} -s -w" ./app && \
echo "linux-arm64" && GOOS=linux GOARCH=arm64 go build -o cronn.linux-arm64 -ldflags "-X main.revision=${version} -s -w" ./app && \
echo "windows-amd64" && GOOS=windows GOARCH=amd64 go build -o cronn.windows-amd64.exe -ldflags "-X main.revision=${version} -s -w" ./app && \
echo "darwin-amd64" && GOOS=darwin GOARCH=amd64 go build -o cronn.darwin-amd64 -ldflags "-X main.revision=${version} -s -w" ./app && \
echo "freebsd-amd64" && GOOS=freebsd GOARCH=amd64 go build -o cronn.freebsd-amd64 -ldflags "-X main.revision=${version} -s -w" ./app
RUN goreleaser --snapshot --skip-publish --rm-dist

FROM alpine
COPY --from=build /build/dist/ /dist/
RUN \
apk add --no-cache --update zip && \
tar cvzf cronn.linux-amd64.tar.gz cronn.linux-amd64 LICENSE README.md && \
tar cvzf cronn.linux-386.tar.gz cronn.linux-386 LICENSE README.md && \
tar cvzf cronn.linux-arm.tar.gz cronn.linux-arm LICENSE README.md && \
tar cvzf cronn.linux-arm64.tar.gz cronn.linux-arm64 LICENSE README.md && \
tar cvzf cronn.darwin-amd64.tar.gz cronn.darwin-amd64 LICENSE README.md && \
tar cvzf cronn.freebsd-amd64.tar.gz cronn.freebsd-amd64 LICENSE README.md && \
zip cronn.windows-amd64.zip cronn.windows-amd64.exe LICENSE README.md
mkdir -p /artifacts && \
cp /dist/*.gz /artifacts/ && \
cp /dist/*.zip /artifacts/ && \
cp /dist/*.txt /artifacts/ && \
ls -la /artifacts/*

FROM alpine
COPY --from=build /build/cronn.* /artifacts/
RUN ls -la /artifacts/*
CMD ["sleep", "100"]
13 changes: 4 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
docker:
docker build -t umputun/cronn .

bin:
dist:
- @mkdir -p dist
docker build -f Dockerfile.artifacts -t cronn.bin .
- @docker rm -f cronn.bin 2>/dev/null || exit 0
- @mkdir -p bin
docker run -d --name=cronn.bin cronn.bin
docker cp cronn.bin:/artifacts/cronn.linux-amd64.tar.gz bin/cronn.linux-amd64.tar.gz
docker cp cronn.bin:/artifacts/cronn.linux-386.tar.gz bin/cronn.linux-386.tar.gz
docker cp cronn.bin:/artifacts/cronn.linux-arm64.tar.gz bin/cronn.linux-arm64.tar.gz
docker cp cronn.bin:/artifacts/cronn.darwin-amd64.tar.gz bin/cronn.darwin-amd64.tar.gz
docker cp cronn.bin:/artifacts/cronn.freebsd-amd64.tar.gz bin/cronn.freebsd-amd64.tar.gz
docker cp cronn.bin:/artifacts/cronn.windows-amd64.zip bin/cronn.windows-amd64.zip
docker cp cronn.bin:/artifacts dist/
docker rm -f cronn.bin

race_test:
cd app && go test -race -mod=vendor -timeout=60s -count 1 ./...

.PHONY: bin docker
.PHONY: dist docker race_test
5 changes: 2 additions & 3 deletions app/crontab/crontab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func TestParser_Changes(t *testing.T) {
assert.Len(t, jobs, 2)

time.AfterFunc(time.Millisecond*500, func() {
_, err = tmp.WriteString("3 * * * * ls\n")
require.NoError(t, err)
_, e := tmp.WriteString("3 * * * * ls\n")
require.NoError(t, e)
})

ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
Expand All @@ -84,5 +84,4 @@ func TestParser_Changes(t *testing.T) {
jobs, err = ctab.List()
require.NoError(t, err)
assert.Len(t, jobs, 3)

}
4 changes: 2 additions & 2 deletions cronn.service
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ StartLimitIntervalSec=0
Type=simple
Restart=always
RestartSec=1
User=<set your user here>
ExecStart=/opt/cronn/cronn -f /opt/cronn/crontab -u
User=root
ExecStart=/usr/bin/cronn -f /etc/cronntab -u

[Install]
WantedBy=multi-user.target
8 changes: 4 additions & 4 deletions crontab.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*/5 * * * * ls -la .
*/2 1-18 * * * export
*/1 * * * * echo {{.YYYYMMDD}}
*/1 * * * * something blah bad
# */5 * * * * ls -la .
# */2 1-18 * * * export
# */1 * * * * echo {{.YYYYMMDD}}
# @every 1h15m something blah bad
3 changes: 3 additions & 0 deletions scripts/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
systemctl start cronn
systemctl enable cronn
3 changes: 3 additions & 0 deletions scripts/preremove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
systemctl stop cronn
systemctl disable cronn

0 comments on commit 815d505

Please sign in to comment.