Skip to content

Commit b657da5

Browse files
committed
set up Dockerfile and workflow
1 parent e039f43 commit b657da5

8 files changed

Lines changed: 438 additions & 355 deletions

File tree

.env

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
GO_VERSION=1.26
2-
NIGHTLY_TAG=nightly
3-
NODE_VERSION=24
4-
REPO_AUTHOR_EMAIL=ayo@freshman.tech
5-
REPO_AUTHOR_NAME=Ayooluwa Isaiah
6-
REPO_BINARY_NAME=f2
7-
REPO_DESCRIPTION=F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely
8-
REPO_MAINTAINER=Ayooluwa Isaiah <ayo@freshman.tech>
9-
REPO_OWNER=ayoisaiah
10-
REPO_WEBSITE=https://f2.freshman.tech
1+
GO_VERSION="1.26.1"
2+
NIGHTLY_TAG="nightly"
3+
NODE_VERSION="24"
4+
REPO_AUTHOR_EMAIL="ayo@freshman.tech"
5+
REPO_AUTHOR_NAME="Ayooluwa Isaiah"
6+
REPO_BINARY_NAME="f2"
7+
REPO_DESCRIPTION="F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely"
8+
REPO_MAINTAINER="Ayooluwa Isaiah <ayo@freshman.tech>"
9+
REPO_OWNER="ayoisaiah"
10+
REPO_WEBSITE="https://f2.freshman.tech"

.github/workflows/docker.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Docker Build and Push
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- v*
9+
pull_request:
10+
branches:
11+
- master
12+
workflow_dispatch:
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
permissions:
19+
contents: read
20+
packages: write
21+
22+
jobs:
23+
docker:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Load .env file
30+
uses: xom9ikk/dotenv@v2.3.0
31+
with:
32+
load-mode: strict
33+
34+
- name: Set up QEMU
35+
uses: docker/setup-qemu-action@v3
36+
37+
- name: Set up Docker Buildx
38+
uses: docker/setup-buildx-action@v3
39+
40+
- name: Login to GHCR
41+
if: github.event_name != 'pull_request'
42+
uses: docker/login-action@v3
43+
with:
44+
registry: ghcr.io
45+
username: ${{ github.repository_owner }}
46+
password: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Docker Metadata
49+
id: meta
50+
uses: docker/metadata-action@v5
51+
with:
52+
images: ghcr.io/${{ github.repository }}
53+
tags: |
54+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
55+
type=semver,pattern={{version}}
56+
type=semver,pattern={{major}}.{{minor}}
57+
type=ref,event=pr
58+
59+
- name: Build and push
60+
uses: docker/build-push-action@v6
61+
with:
62+
context: .
63+
platforms: linux/amd64,linux/arm64
64+
push: ${{ github.event_name != 'pull_request' }}
65+
tags: ${{ steps.meta.outputs.tags }}
66+
labels: ${{ steps.meta.outputs.labels }}
67+
build-args: |
68+
GO_VERSION=${{ env.GO_VERSION }}
69+
REPO_OWNER=${{ env.REPO_OWNER }}
70+
REPO_BINARY_NAME=${{ env.REPO_BINARY_NAME }}
71+
REPO_DESCRIPTION=${{ env.REPO_DESCRIPTION }}
72+
cache-from: type=gha
73+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
1-
FROM golang:1.25.0-alpine AS builder
1+
# Build stage
2+
ARG GO_VERSION=1.26.1
3+
FROM golang:${GO_VERSION}-alpine AS builder
24

5+
# Set the working directory
36
WORKDIR /build
47

5-
COPY go.mod go.sum ./
8+
# Install build dependencies
9+
RUN apk add --no-cache git
610

11+
# Copy and download dependencies
12+
COPY go.mod go.sum ./
713
RUN go mod download
814

9-
COPY . ./
15+
# Copy the source code
16+
COPY . .
17+
18+
# Build the binary with optimizations
19+
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -trimpath -o /usr/bin/f2 ./cmd/f2
20+
21+
# Final stage
22+
FROM alpine:3.21 AS final
1023

11-
RUN go build -o /usr/bin/f2 ./cmd/f2...
24+
# Metadata arguments
25+
ARG REPO_OWNER=ayoisaiah
26+
ARG REPO_BINARY_NAME=f2
27+
ARG REPO_DESCRIPTION="F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely"
1228

13-
FROM alpine:3.22 AS final
29+
# Metadata labels
30+
LABEL org.opencontainers.image.source="https://github.com/${REPO_OWNER}/${REPO_BINARY_NAME}"
31+
LABEL org.opencontainers.image.description="${REPO_DESCRIPTION}"
32+
LABEL org.opencontainers.image.licenses="MIT"
1433

34+
# Install runtime dependencies (exiftool)
1535
RUN apk add --no-cache exiftool
1636

37+
# Set the working directory
1738
WORKDIR /app
1839

40+
# Copy the binary from the builder
1941
COPY --from=builder /usr/bin/f2 /usr/bin/f2
2042

21-
# Run the f2 command when the container starts
43+
# Set the entrypoint
2244
ENTRYPOINT ["f2"]

go.mod

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/ayoisaiah/f2/v2
22

3-
go 1.25.0
3+
go 1.26.1
44

55
require (
66
github.com/barasher/go-exiftool v1.10.0
@@ -20,6 +20,7 @@ require (
2020
github.com/djherbis/times v1.6.0
2121
github.com/jessevdk/go-flags v1.6.1
2222
github.com/jinzhu/copier v0.4.0
23+
github.com/lmittmann/tint v1.1.2
2324
github.com/maja42/goval v1.6.0
2425
github.com/maruel/natural v1.1.1
2526
github.com/mattn/go-isatty v0.0.20
@@ -29,37 +30,26 @@ require (
2930
github.com/stretchr/testify v1.10.0
3031
github.com/urfave/cli/v3 v3.4.1
3132
go.withmatt.com/size v0.0.0-20250220224316-11aee5773e67
33+
golang.org/x/sync v0.20.0
3234
)
3335

3436
require (
3537
atomicgo.dev/cursor v0.2.0 // indirect
3638
atomicgo.dev/keyboard v0.2.9 // indirect
3739
atomicgo.dev/schedule v0.1.0 // indirect
38-
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
3940
github.com/cespare/xxhash v1.1.0 // indirect
40-
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
41-
github.com/charmbracelet/lipgloss v1.1.0 // indirect
42-
github.com/charmbracelet/log v0.4.2 // indirect
43-
github.com/charmbracelet/x/ansi v0.8.0 // indirect
44-
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
45-
github.com/charmbracelet/x/term v0.2.1 // indirect
4641
github.com/containerd/console v1.0.4 // indirect
4742
github.com/davecgh/go-spew v1.1.1 // indirect
48-
github.com/go-logfmt/logfmt v0.6.0 // indirect
4943
github.com/gookit/color v1.5.4 // indirect
5044
github.com/kr/pretty v0.3.1 // indirect
5145
github.com/lithammer/fuzzysearch v1.1.8 // indirect
52-
github.com/lmittmann/tint v1.1.2 // indirect
53-
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
5446
github.com/mattn/go-runewidth v0.0.16 // indirect
55-
github.com/muesli/termenv v0.16.0 // indirect
5647
github.com/pmezard/go-difflib v1.0.0 // indirect
5748
github.com/rivo/uniseg v0.4.7 // indirect
5849
github.com/rogpeppe/go-internal v1.14.1 // indirect
5950
github.com/sergi/go-diff v1.3.1 // indirect
6051
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
6152
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
62-
golang.org/x/sync v0.20.0 // indirect
6353
golang.org/x/term v0.32.0 // indirect
6454
gopkg.in/yaml.v3 v3.0.1 // indirect
6555
)

go.sum

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,10 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
2222
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA=
2323
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw=
2424
github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk=
25-
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
26-
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
2725
github.com/barasher/go-exiftool v1.10.0 h1:f5JY5jc42M7tzR6tbL9508S2IXdIcG9QyieEXNMpIhs=
2826
github.com/barasher/go-exiftool v1.10.0/go.mod h1:F9s/a3uHSM8YniVfwF+sbQUtP8Gmh9nyzigNF+8vsWo=
2927
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
3028
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
31-
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
32-
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
33-
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
34-
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
35-
github.com/charmbracelet/log v0.4.2 h1:hYt8Qj6a8yLnvR+h7MwsJv/XvmBJXiueUcI3cIxsyig=
36-
github.com/charmbracelet/log v0.4.2/go.mod h1:qifHGX/tc7eluv2R6pWIpyHDDrrb/AG71Pf2ysQu5nw=
37-
github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE=
38-
github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=
39-
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
40-
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
41-
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
42-
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
4329
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
4430
github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro=
4531
github.com/containerd/console v1.0.4/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
@@ -51,8 +37,6 @@ github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8 h1:OtSeLS5y0Uy01jaKK4m
5137
github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8/go.mod h1:apkPC/CR3s48O2D7Y++n1XWEpgPNNCjXYga3PPbJe2E=
5238
github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
5339
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
54-
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
55-
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
5640
github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=
5741
github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo=
5842
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
@@ -79,8 +63,6 @@ github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8
7963
github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4=
8064
github.com/lmittmann/tint v1.1.2 h1:2CQzrL6rslrsyjqLDwD11bZ5OpLBPU+g3G/r5LSfS8w=
8165
github.com/lmittmann/tint v1.1.2/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE=
82-
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
83-
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
8466
github.com/maja42/goval v1.6.0 h1:MuLTfgPuaEyGQTchYQTv2QvAiHbS2YjtOjviD2ymijE=
8567
github.com/maja42/goval v1.6.0/go.mod h1:LDMwF8ocOwIsMZdwoyHC/3UpV8ABDwEzalxkVV2z/rI=
8668
github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo=
@@ -92,8 +74,6 @@ github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRC
9274
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
9375
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
9476
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
95-
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
96-
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
9777
github.com/nicksnyder/go-i18n/v2 v2.6.0 h1:C/m2NNWNiTB6SK4Ao8df5EWm3JETSTIGNXBpMJTxzxQ=
9878
github.com/nicksnyder/go-i18n/v2 v2.6.0/go.mod h1:88sRqr0C6OPyJn0/KRNaEz1uWorjxIKP7rUUcvycecE=
9979
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
@@ -135,10 +115,6 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
135115
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
136116
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
137117
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
138-
github.com/urfave/cli/v3 v3.3.3 h1:byCBaVdIXuLPIDm5CYZRVG6NvT7tv1ECqdU4YzlEa3I=
139-
github.com/urfave/cli/v3 v3.3.3/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
140-
github.com/urfave/cli/v3 v3.3.10-0.20250809215531-db7d18f23ca8 h1:b2LrxY5zBCO10B6kRxGVPYE/hTi3Oe7i4uAW2I3hYG0=
141-
github.com/urfave/cli/v3 v3.3.10-0.20250809215531-db7d18f23ca8/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
142118
github.com/urfave/cli/v3 v3.4.1 h1:1M9UOCy5bLmGnuu1yn3t3CB4rG79Rtoxuv1sPhnm6qM=
143119
github.com/urfave/cli/v3 v3.4.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
144120
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=

justfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
set dotenv-load
2+
13
APP := "f2"
4+
REPO_OWNER := env_var_or_default("REPO_OWNER", "ayoisaiah")
5+
REPO_BINARY_NAME := env_var_or_default("REPO_BINARY_NAME", "f2")
26
toolprefix := "go tool -modfile=" + justfile_directory() + "/tools.mod"
37
toolsmod := "-modfile=" + justfile_directory() + "/tools.mod"
48
# Run all tests
@@ -16,6 +20,14 @@ release-snapshot:
1620
release:
1721
@{{toolprefix}} goreleaser release --clean
1822

23+
docker:
24+
@docker build \
25+
--build-arg GO_VERSION={{env_var("GO_VERSION")}} \
26+
--build-arg REPO_OWNER={{REPO_OWNER}} \
27+
--build-arg REPO_BINARY_NAME={{REPO_BINARY_NAME}} \
28+
--build-arg REPO_DESCRIPTION="{{env_var("REPO_DESCRIPTION")}}" \
29+
-t {{REPO_OWNER}}/{{REPO_BINARY_NAME}}:latest .
30+
1931
update-golden filter='.*':
2032
@go test ./... -update -json -run={{filter}} | {{toolprefix}} gotestfmt
2133

0 commit comments

Comments
 (0)