Skip to content

Commit

Permalink
feat: add container builds locally and through ci (#39)
Browse files Browse the repository at this point in the history
* add containerization builds locally & through CI
* multi-platform architecture
* refactors various files to improve efficiency and development experience
* sets runners to be bigger for performance

---------
Co-authored-by: Adriel Perkins <adriel@adrielperkins.dev>
Co-authored-by: Mitchell Phillips <mitchellp@liatrio.com>
Co-authored-by: Patrick Paulino <patrickp@liatrio.com>
  • Loading branch information
adrielp authored Jul 18, 2023
1 parent 0869ad3 commit ca16db8
Show file tree
Hide file tree
Showing 15 changed files with 385 additions and 195 deletions.
116 changes: 105 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ on:
branches: [main]

jobs:
lint:
prep-env:
name: prepare environment
strategy:
matrix:
go: ['1.19']
os: [ubuntu-latest, macos-latest]
name: lint
runs-on: ${{ matrix.os }}
runs-on:
group: bigger
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
Expand All @@ -25,16 +28,61 @@ jobs:
- name: Make install-tools
run: make install-tools

- name: Make cibuild
run: make cibuild

- name: Cache directories
uses: actions/cache@v2
with:
path: |
~/go/bin
./build
./tmp
key: ${{ runner.os }}-make-${{ hashFiles('**/Makefile') }}
restore-keys: |
${{ runner.os }}-make-
lint:
needs: [prep-env]
strategy:
matrix:
go: ['1.19']
name: lint
runs-on:
group: bigger
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
cache: false

- name: Restore cache
uses: actions/cache@v2
with:
path: |
~/go/bin
./build
./tmp
key: ${{ runner.os }}-make-${{ hashFiles('**/Makefile') }}
restore-keys: |
${{ runner.os }}-make-
- name: Make lint-all
run: make lint-all

build:
name: build
needs: [prep-env]
strategy:
matrix:
go: ['1.19']
os: [ubuntu-latest, macos-latest]
name: build
runs-on: ${{ matrix.os }}
runs-on:
group: bigger
steps:
- name: Check out code
uses: actions/checkout@v3
Expand All @@ -44,16 +92,62 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.19'
go-version: ${{ matrix.go }}
cache: false

- name: Make cibuild
run: make cibuild
- name: Restore cache
uses: actions/cache@v2
with:
path: |
~/go/bin
./build
./tmp
key: ${{ runner.os }}-make-${{ hashFiles('**/Makefile') }}
restore-keys: |
${{ runner.os }}-make-
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --clean --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

test:
needs: [prep-env]
strategy:
matrix:
go: ['1.19']
name: test
runs-on:
group: bigger
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
cache: false

- name: Make test-all
run: make test-all

go-semantic-release:
if: ${{ github.ref == 'refs/heads/main' }}
needs: [lint, build]
runs-on: ubuntu-latest
runs-on:
group: bigger
permissions:
contents: write
steps:
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,24 @@ jobs:
- name: Fetch all tags
run: git fetch --force --tags

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
Expand Down
121 changes: 92 additions & 29 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,45 +1,108 @@
---
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
hooks:
# You may remove this if you don't use go modules.
# - go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
- make cibuild
- go generate ./...
- make cibuild
builds:
- dir: ./build
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
- dir: ./build
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows

dockers:
- goos: linux
goarch: '386'
image_templates:
- ghcr.io/liatrio/liatrio-otel-collector:{{ .Version }}-386
- ghcr.io/liatrio/liatrio-otel-collector:latest-386
extra_files:
- config/config.yaml
use: buildx
build_flag_templates:
- --pull
- --platform=linux/386
- --label=org.opencontainers.image.created={{.Date}}
- --label=org.opencontainers.image.name={{.ProjectName}}
- --label=org.opencontainers.image.revision={{.FullCommit}}
- --label=org.opencontainers.image.version={{.Version}}
- --label=org.opencontainers.image.source={{.GitURL}}
- goos: linux
goarch: amd64
image_templates:
- ghcr.io/liatrio/liatrio-otel-collector:{{ .Version }}-amd64
- ghcr.io/liatrio/liatrio-otel-collector:latest-amd64
extra_files:
- config/config.yaml
use: buildx
build_flag_templates:
- --pull
- --platform=linux/amd64
- --label=org.opencontainers.image.created={{.Date}}
- --label=org.opencontainers.image.name={{.ProjectName}}
- --label=org.opencontainers.image.revision={{.FullCommit}}
- --label=org.opencontainers.image.version={{.Version}}
- --label=org.opencontainers.image.source={{.GitURL}}
- goos: linux
goarch: arm64
image_templates:
- ghcr.io/liatrio/liatrio-otel-collector:{{ .Version }}-arm64
- ghcr.io/liatrio/liatrio-otel-collector:latest-arm64
extra_files:
- config/config.yaml
use: buildx
build_flag_templates:
- --pull
- --platform=linux/arm64
- --label=org.opencontainers.image.created={{.Date}}
- --label=org.opencontainers.image.name={{.ProjectName}}
- --label=org.opencontainers.image.revision={{.FullCommit}}
- --label=org.opencontainers.image.version={{.Version}}
- --label=org.opencontainers.image.source={{.GitURL}}

docker_manifests:
- name_template: liatrio/liatrio-otel-collector:{{ .Version }}
image_templates:
- liatrio/liatrio-otel-collector:{{ .Version }}-386
- liatrio/liatrio-otel-collector:{{ .Version }}-amd64
- liatrio/liatrio-otel-collector:{{ .Version }}-arm64
- name_template: liatrio/liatrio-otel-collector:latest
image_templates:
- liatrio/liatrio-otel-collector:latest-386
- liatrio/liatrio-otel-collector:latest-amd64
- liatrio/liatrio-otel-collector:latest-arm64

archives:
- format: tar.gz
- 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
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'
name_template: checksums.txt
snapshot:
name_template: "{{ incpatch .Version }}-next"
name_template: '{{ incpatch .Version }}-next'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
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.
Expand Down
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM alpine:3.18.2 as cacerts
RUN apk --update add --no-cache ca-certificates

FROM scratch

ARG BIN_PATH=liatrio-otel-collector

ARG UID=10001
USER ${UID}

COPY --from=cacerts /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --chmod=755 ${BIN_PATH} /usr/bin/liatrio-col
COPY config/config.yaml /etc/liatrio-otel/config.yaml


ENTRYPOINT ["/usr/bin/liatrio-col"]
CMD ["--config=/etc/liatrio-otel/config.yaml"]
EXPOSE 4317 55678 55679
Loading

0 comments on commit ca16db8

Please sign in to comment.