Skip to content

Commit

Permalink
chore(ci): binaries + docker images build update (#804)
Browse files Browse the repository at this point in the history
* Updating the build logic
* fix ci-info update
* Adding scratch Dockerfile and renaming the existing one to Dockerfile.alpine
  • Loading branch information
fclairamb authored Sep 23, 2022
1 parent 8138b02 commit b675aed
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 119 deletions.
10 changes: 10 additions & 0 deletions .ci-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://raw.githubusercontent.com/fclairamb/ci-info/main/config-schema.json",
"version_input_git_tag": {
"pattern": "^v?([0-9.]+)$"
},
"templates": [{
"input_file": "build.go.tpl",
"output_file": "build.go"
}]
}
65 changes: 0 additions & 65 deletions .github/workflows/cross-build.yml

This file was deleted.

133 changes: 82 additions & 51 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,87 @@
name: Build docker images

on:
push:
# branches:
# - "**"
tags:
- "v*.*.*"
# pull_request:
push:
branches: # At least when doing some tests
- "**"
tags:
- "v*.*.*"
# pull_request:

jobs:
multi-registries:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v4
with:
images: fclairamb/ftpserver
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
if: github.repository == 'fclairamb/ftpserver'
uses: docker/login-action@v2
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: github.repository == 'fclairamb/ftpserver'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64
push: ${{ github.repository == 'fclairamb/ftpserver' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-and-push:
strategy:
matrix:
type: ["", "alpine"]
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Change version
run: |
curl -L https://github.com/fclairamb/ci-info/releases/download/v0.4.4/ci-info_0.4.4_linux_amd64.tar.gz | tar -zx
./ci-info
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v4
with:
images: |
fclairamb/ftpserver
ghcr.io/fclairamb/ftpserver
flavor: |
suffix=${{ matrix.type != '' && format('-{0}', matrix.type) || '' }}
latest=false
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=semver,suffix=,pattern=${{ matrix.type != '' && matrix.type || 'latest' }}
type=ref,event=branch
type=ref,event=pr
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.type }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
if: github.repository == 'fclairamb/ftpserver'
uses: docker/login-action@v2
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: github.repository == 'fclairamb/ftpserver'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Build and push (scratch)
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile${{ matrix.type != '' && format('.{0}', matrix.type) || '' }}
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
push: ${{ github.repository == 'fclairamb/ftpserver' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

build-and-push-status:
needs: build-and-push
runs-on: ubuntu-22.04
steps:
- run: echo 'All good'
25 changes: 25 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: goreleaser

on:
push:

jobs:
goreleaser:
runs-on: ubuntu-22.04
steps:
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v3
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.DS_Store
ftpserver
.idea
.vscode
*.json
ci-info
.idea/
.vscode/
*.pem
ftpserver.json
gdrive_token_gdrive.json
__debug__bin
3 changes: 3 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
builds:
- ldflags:
- -s -w -X main.BuildVersion={{.Version}} -X main.Commit={{.Commit}} -X main.BuildDate={{.Date}}
20 changes: 20 additions & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Should be started with:
# docker run -ti -p 2121-2130:2121-2130 fclairamb/ftpserver

# Preparing the build environment
FROM golang:1.19-alpine AS builder
ENV GOFLAGS="-mod=readonly"
RUN apk add --update --no-cache bash ca-certificates curl git
RUN mkdir -p /workspace
WORKDIR /workspace

# Building
COPY . .
RUN CGO_ENABLED=0 go build -mod=readonly -ldflags='-w -s' -v -o ftpserver

# Preparing the final image
FROM scratch
WORKDIR /app
EXPOSE 2121-2130
COPY --from=builder /workspace/ftpserver /bin/ftpserver
ENTRYPOINT [ "/bin/ftpserver" ]
12 changes: 12 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

var (
// BuildVersion is the current version of the program
BuildVersion = ""

// BuildDate is the time the program was built
BuildDate = ""

// Commit is the git hash of the program
Commit = ""
)
12 changes: 12 additions & 0 deletions build.go.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

var (
// BuildVersion is the current version of the program
BuildVersion = "{{ .Version }}"

// BuildDate is the time the program was built
BuildDate = "{{ .BuildDate }}"

// Commit is the git hash of the program
Commit = "{{ .GitCommitHashShort }}"
)
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func main() {
"caller", gokit.GKDefaultCaller,
)

logger.Info("FTP server", "version", BuildVersion, "date", BuildDate, "commit", Commit)

autoCreate := onlyConf

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

0 comments on commit b675aed

Please sign in to comment.