Skip to content

Commit b675aed

Browse files
authored
chore(ci): binaries + docker images build update (#804)
* Updating the build logic * fix ci-info update * Adding scratch Dockerfile and renaming the existing one to Dockerfile.alpine
1 parent 8138b02 commit b675aed

File tree

10 files changed

+171
-119
lines changed

10 files changed

+171
-119
lines changed

.ci-info.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/fclairamb/ci-info/main/config-schema.json",
3+
"version_input_git_tag": {
4+
"pattern": "^v?([0-9.]+)$"
5+
},
6+
"templates": [{
7+
"input_file": "build.go.tpl",
8+
"output_file": "build.go"
9+
}]
10+
}

.github/workflows/cross-build.yml

Lines changed: 0 additions & 65 deletions
This file was deleted.

.github/workflows/docker.yml

Lines changed: 82 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,87 @@
11
name: Build docker images
22

33
on:
4-
push:
5-
# branches:
6-
# - "**"
7-
tags:
8-
- "v*.*.*"
9-
# pull_request:
4+
push:
5+
branches: # At least when doing some tests
6+
- "**"
7+
tags:
8+
- "v*.*.*"
9+
# pull_request:
1010

1111
jobs:
12-
multi-registries:
13-
runs-on: ubuntu-20.04
14-
steps:
15-
- name: Checkout
16-
uses: actions/checkout@v3
17-
- name: Docker meta
18-
id: docker_meta
19-
uses: crazy-max/ghaction-docker-meta@v4
20-
with:
21-
images: fclairamb/ftpserver
22-
- name: Set up QEMU
23-
uses: docker/setup-qemu-action@v2
24-
- name: Set up Docker Buildx
25-
uses: docker/setup-buildx-action@v2
26-
- name: Cache Docker layers
27-
uses: actions/cache@v3
28-
with:
29-
path: /tmp/.buildx-cache
30-
key: ${{ runner.os }}-buildx-${{ github.sha }}
31-
restore-keys: |
32-
${{ runner.os }}-buildx-
33-
- name: Login to DockerHub
34-
if: github.repository == 'fclairamb/ftpserver'
35-
uses: docker/login-action@v2
36-
with:
37-
username: ${{ github.repository_owner }}
38-
password: ${{ secrets.DOCKERHUB_TOKEN }}
39-
- name: Login to GitHub Container Registry
40-
if: github.repository == 'fclairamb/ftpserver'
41-
uses: docker/login-action@v2
42-
with:
43-
registry: ghcr.io
44-
username: ${{ github.repository_owner }}
45-
password: ${{ secrets.CR_PAT }}
46-
- name: Build and push
47-
uses: docker/build-push-action@v3
48-
with:
49-
context: .
50-
file: ./Dockerfile
51-
platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64
52-
push: ${{ github.repository == 'fclairamb/ftpserver' }}
53-
tags: ${{ steps.docker_meta.outputs.tags }}
54-
labels: ${{ steps.docker_meta.outputs.labels }}
55-
cache-from: type=local,src=/tmp/.buildx-cache
56-
cache-to: type=local,dest=/tmp/.buildx-cache
12+
build-and-push:
13+
strategy:
14+
matrix:
15+
type: ["", "alpine"]
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0
22+
- name: Setup go
23+
uses: actions/setup-go@v3
24+
with:
25+
go-version: 1.19
26+
- name: Change version
27+
run: |
28+
curl -L https://github.com/fclairamb/ci-info/releases/download/v0.4.4/ci-info_0.4.4_linux_amd64.tar.gz | tar -zx
29+
./ci-info
30+
- name: Docker meta
31+
id: docker_meta
32+
uses: docker/metadata-action@v4
33+
with:
34+
images: |
35+
fclairamb/ftpserver
36+
ghcr.io/fclairamb/ftpserver
37+
flavor: |
38+
suffix=${{ matrix.type != '' && format('-{0}', matrix.type) || '' }}
39+
latest=false
40+
tags: |
41+
type=semver,pattern={{version}}
42+
type=semver,pattern={{major}}.{{minor}}
43+
type=semver,pattern={{major}}
44+
type=semver,suffix=,pattern=${{ matrix.type != '' && matrix.type || 'latest' }}
45+
type=ref,event=branch
46+
type=ref,event=pr
47+
- name: Set up QEMU
48+
uses: docker/setup-qemu-action@v2
49+
- name: Set up Docker Buildx
50+
uses: docker/setup-buildx-action@v2
51+
- name: Cache Docker layers
52+
uses: actions/cache@v3
53+
with:
54+
path: /tmp/.buildx-cache
55+
key: ${{ runner.os }}-buildx-${{ matrix.type }}-${{ github.sha }}
56+
restore-keys: |
57+
${{ runner.os }}-buildx-
58+
- name: Login to DockerHub
59+
if: github.repository == 'fclairamb/ftpserver'
60+
uses: docker/login-action@v2
61+
with:
62+
username: ${{ github.repository_owner }}
63+
password: ${{ secrets.DOCKERHUB_TOKEN }}
64+
- name: Login to GitHub Container Registry
65+
if: github.repository == 'fclairamb/ftpserver'
66+
uses: docker/login-action@v2
67+
with:
68+
registry: ghcr.io
69+
username: ${{ github.repository_owner }}
70+
password: ${{ secrets.CR_PAT }}
71+
- name: Build and push (scratch)
72+
uses: docker/build-push-action@v3
73+
with:
74+
context: .
75+
file: ./Dockerfile${{ matrix.type != '' && format('.{0}', matrix.type) || '' }}
76+
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
77+
push: ${{ github.repository == 'fclairamb/ftpserver' }}
78+
tags: ${{ steps.docker_meta.outputs.tags }}
79+
labels: ${{ steps.docker_meta.outputs.labels }}
80+
cache-from: type=local,src=/tmp/.buildx-cache
81+
cache-to: type=local,dest=/tmp/.buildx-cache
82+
83+
build-and-push-status:
84+
needs: build-and-push
85+
runs-on: ubuntu-22.04
86+
steps:
87+
- run: echo 'All good'

.github/workflows/goreleaser.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
goreleaser:
8+
runs-on: ubuntu-22.04
9+
steps:
10+
-
11+
name: Checkout
12+
uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
-
16+
name: Set up Go
17+
uses: actions/setup-go@v3
18+
-
19+
name: Run GoReleaser
20+
uses: goreleaser/goreleaser-action@v3
21+
with:
22+
version: latest
23+
args: release --rm-dist
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
.DS_Store
22
ftpserver
3-
.idea
4-
.vscode
5-
*.json
3+
ci-info
4+
.idea/
5+
.vscode/
66
*.pem
7+
ftpserver.json
8+
gdrive_token_gdrive.json
79
__debug__bin

.goreleaser.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
builds:
2+
- ldflags:
3+
- -s -w -X main.BuildVersion={{.Version}} -X main.Commit={{.Commit}} -X main.BuildDate={{.Date}}

Dockerfile.alpine

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Should be started with:
2+
# docker run -ti -p 2121-2130:2121-2130 fclairamb/ftpserver
3+
4+
# Preparing the build environment
5+
FROM golang:1.19-alpine AS builder
6+
ENV GOFLAGS="-mod=readonly"
7+
RUN apk add --update --no-cache bash ca-certificates curl git
8+
RUN mkdir -p /workspace
9+
WORKDIR /workspace
10+
11+
# Building
12+
COPY . .
13+
RUN CGO_ENABLED=0 go build -mod=readonly -ldflags='-w -s' -v -o ftpserver
14+
15+
# Preparing the final image
16+
FROM scratch
17+
WORKDIR /app
18+
EXPOSE 2121-2130
19+
COPY --from=builder /workspace/ftpserver /bin/ftpserver
20+
ENTRYPOINT [ "/bin/ftpserver" ]

build.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
var (
4+
// BuildVersion is the current version of the program
5+
BuildVersion = ""
6+
7+
// BuildDate is the time the program was built
8+
BuildDate = ""
9+
10+
// Commit is the git hash of the program
11+
Commit = ""
12+
)

build.go.tpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
var (
4+
// BuildVersion is the current version of the program
5+
BuildVersion = "{{ .Version }}"
6+
7+
// BuildDate is the time the program was built
8+
BuildDate = "{{ .BuildDate }}"
9+
10+
// Commit is the git hash of the program
11+
Commit = "{{ .GitCommitHashShort }}"
12+
)

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func main() {
3737
"caller", gokit.GKDefaultCaller,
3838
)
3939

40+
logger.Info("FTP server", "version", BuildVersion, "date", BuildDate, "commit", Commit)
41+
4042
autoCreate := onlyConf
4143

4244
// The general idea here is that if you start it without any arg, you're probably doing a local quick&dirty run

0 commit comments

Comments
 (0)