Switch from goreleaser to manual docker builds

This commit is contained in:
Evan Fiordeliso 2023-08-12 13:24:26 -04:00
parent 81120bf333
commit 70223a8040
3 changed files with 57 additions and 130 deletions

View File

@ -1,115 +0,0 @@
---
project_name: ytdl-web
env:
- BASE_PKG=go.fifitido.net/ytdl-web
gitea_urls:
api: https://git.fifitido.net/api/v1
download: https://git.fifitido.net
before:
hooks:
- tidy
builds:
- id: ytdl-web_linux
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- arm64
- arm
goarm:
- "7"
- "6"
ldflags:
- -X {{ .Env.BASE_PKG }}/version.Version={{.Version}}
- -X {{ .Env.BASE_PKG }}/version.Build={{.ShortCommit}}
- -X {{ .Env.BASE_PKG }}/version.BuildDate={{.Date}}
- -X {{ .Env.BASE_PKG }}/version.BuiltBy=goreleaser
- env:
- CGO_ENABLED=0
goos:
- windows
- darwin
ldflags:
- -X {{ .Env.BASE_PKG }}/version.Version={{.Version}}
- -X {{ .Env.BASE_PKG }}/version.Build={{.ShortCommit}}
- -X {{ .Env.BASE_PKG }}/version.BuildDate={{.Date}}
- -X {{ .Env.BASE_PKG }}/version.BuiltBy=goreleaser
dockers:
- image_templates:
- &amd64_image git.fifitido.net/apps/{{.ProjectName}}:{{.Tag}}-amd64
use: buildx
dockerfile: Dockerfile
goos: linux
goarch: amd64
build_flag_templates:
- --platform=linux/amd64
- image_templates:
- &arm64v8_image git.fifitido.net/apps/{{.ProjectName}}:{{.Tag}}-arm64v8
use: buildx
dockerfile: Dockerfile
goos: linux
goarch: arm64
build_flag_templates:
- --platform=linux/arm64/v8
- image_templates:
- &armv7_image git.fifitido.net/apps/{{.ProjectName}}:{{.Tag}}-armv7
use: buildx
dockerfile: Dockerfile
goos: linux
goarch: arm
goarm: 7
build_flag_templates:
- --platform=linux/arm/v7
- image_templates:
- &armv6_image git.fifitido.net/apps/{{.ProjectName}}:{{.Tag}}-armv6
use: buildx
dockerfile: Dockerfile
goos: linux
goarch: arm
goarm: 6
build_flag_templates:
- --platform=linux/arm/v6
docker_manifests:
- name_template: git.fifitido.net/apps/{{.ProjectName}}:latest
image_templates:
- *amd64_image
- *arm64v8_image
- *armv7_image
- *armv6_image
- name_template: git.fifitido.net/apps/{{.ProjectName}}:{{.Tag}}
image_templates:
- *amd64_image
- *arm64v8_image
- *armv7_image
- *armv6_image
archives:
- format: tar.gz
# this name template makes the OS and Arch
# compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
checksum:
name_template: checksums.txt
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
# The lines beneath this are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

View File

@ -1,5 +1,27 @@
ARG GOLANG_VERSION="1.20.5"
ARG ALPINE_VERSION="3.18" ARG ALPINE_VERSION="3.18"
FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} AS build
ARG VERSION=latest
ARG BUILD="unknown"
ARG BUILD_DATE="unknown"
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build \
-ldflags="-X $VERSION_PKG.Version=${VERSION}" \
-ldflags="-X $VERSION_PKG.Build=${BUILD}" \
-ldflags="-X $VERSION_PKG.BuildDate=${BUILD_DATE}" \
-ldflags="-X $VERSION_PKG.BuiltBy=dockerfile" \
-o /ytdl-web .
FROM alpine:${ALPINE_VERSION} FROM alpine:${ALPINE_VERSION}
WORKDIR /app WORKDIR /app
@ -7,7 +29,7 @@ WORKDIR /app
ARG YTDLP_VERSION="2023.07.06-r0" ARG YTDLP_VERSION="2023.07.06-r0"
RUN apk add --no-cache yt-dlp==${YTDLP_VERSION} RUN apk add --no-cache yt-dlp==${YTDLP_VERSION}
COPY ytdl-web ./ COPY --from=build /ytdl-web ./
EXPOSE 8080 EXPOSE 8080

View File

@ -6,51 +6,71 @@
env.BINARY_OUT = "./out/ytdl-web"; env.BINARY_OUT = "./out/ytdl-web";
env.VERSION = "1.0.8"; env.VERSION = "1.0.8";
env.VERSION_PKG = "go.fifitido.net/ytdl-web/version"; env.VERSION_PKG = "go.fifitido.net/ytdl-web/version";
env.DOCKER_REGISTRY = "git.fifitido.net";
env.DOCKER_ORG = "apps";
env.DOCKER_PLATFORMS = "linux/amd64,linux/arm64";
env.YTDL_ENV = "Development"; env.YTDL_ENV = "Development";
# https://devenv.sh/packages/ # https://devenv.sh/packages/
packages = with pkgs; [ packages = with pkgs; [
git git
air air
goreleaser
docker docker
docker-compose docker-compose
buildkit
docker-buildx docker-buildx
trunk-io
yt-dlp yt-dlp
]; ];
# https://devenv.sh/scripts/ # https://devenv.sh/scripts/
scripts.deps.exec = "go mod download"; scripts.deps.exec = "go mod download";
scripts.tidy.exec = "go mod tidy"; scripts.tidy.exec = "go mod tidy";
scripts.check.exec = "goreleaser check";
scripts.build-id = "git rev-parse --short HEAD";
scripts.build-date = "date -Iseconds";
scripts.build.exec = '' scripts.build.exec = ''
go build -ldflags=" go build -ldflags="
-X $VERSION_PKG.Version=$VERSION -X $VERSION_PKG.Version=$VERSION
-X $VERSION_PKG.Build=$(git rev-parse --short HEAD) -X $VERSION_PKG.Build=$(build-id)
-X $VERSION_PKG.BuildDate=$(date -Iseconds) -X $VERSION_PKG.BuildDate=$(build-date)
-X $VERSION_PKG.BuiltBy=taskfile -X $VERSION_PKG.BuiltBy=manual
" -o $BINARY_OUT . " -o $BINARY_OUT .
''; '';
scripts.clean.exec = '' scripts.clean.exec = ''
rm -rf ./dist/ ./out/ ./tmp/ rm -rf ./dist/ ./out/ ./tmp/
go clean go clean
''; '';
scripts.release.exec = ''
clean
goreleaser release
'';
scripts.lint.exec = "trunk check"; scripts.lint.exec = "trunk check";
scripts.fmt.exec = "trunk fmt"; scripts.fmt.exec = "trunk fmt";
scripts.docker-image.exec = "echo $DOCKER_REGISTRY/$DOCKER_ORG/$NAME";
scripts.docker-init.exec = ''
docker buildx create \
--name $NAME \
--platform $DOCKER_PLATFORMS
'';
scripts.docker-build-release.exec = ''
docker-init
docker buildx build \
--tag $(docker-image):$VERSION \
--tag $(docker-image):latest \
--platform $DOCKER_PLATFORMS \
--builder $NAME \
--build-arg VERSION=$VERSION
--build-arg BUILD=$(build-id)
--build-arg BUILD_DATE=$(build-date)
'';
enterShell = '' enterShell = ''
echo "Welcome to the $NAME development environment." echo "Welcome to the $NAME development environment."
echo -n "Golang version: $(go version | cut -d ' ' -f 3), " echo -n "Golang version: $(go version | cut -d ' ' -f 3), "
echo -n "Goreleaser version: $(goreleaser --version | tail -n 9 | head -n 1 | cut -c 16-), " echo -n "Docker CLI version: $(docker version -f {{.Client.Version}}), "
echo -n "yt-dlp version: $(yt-dlp --version), " echo -n "Buildx version: $(docker buildx version | cut -d ' ' -f 2), "
echo "Trunk version: $(trunk --version)" echo "yt-dlp version: $(yt-dlp --version)"
''; '';
# https://devenv.sh/languages/ # https://devenv.sh/languages/