mirror of https://github.com/fmartingr/bazaar.git
ci: docker buildx (#8)
* fix: goreleaser main path * ignore dist folder * ci: docker buildx support
This commit is contained in:
parent
5543a19df1
commit
99845f1ad6
|
@ -22,5 +22,9 @@ jobs:
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go_version }}
|
go-version: ${{ matrix.go_version }}
|
||||||
|
|
||||||
- name: Build
|
- name: Run GoReleaser
|
||||||
run: make build
|
uses: goreleaser/goreleaser-action@v2
|
||||||
|
with:
|
||||||
|
distribution: goreleaser
|
||||||
|
version: latest
|
||||||
|
args: build --single-target --snapshot
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
name: "Build Docker"
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
buildx:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
name: Build Docker
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: dist
|
||||||
|
path: dist
|
||||||
|
|
||||||
|
- name: Buildx
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.GITHUB_TOKEN }}" | docker login -u "${{ github.repository_owner }}" --password-stdin ghcr.io
|
||||||
|
REPOSITORY=ghcr.io/${{ github.repository }}
|
||||||
|
|
||||||
|
TAG=latest
|
||||||
|
if [ -z "$(git tag --points-at HEAD)" ]
|
||||||
|
then
|
||||||
|
TAG="dev"
|
||||||
|
fi
|
||||||
|
|
||||||
|
CONTAINER_BUILDX_OPTIONS="--push --output=type=registry --tag $REPOSITORY:$(git describe --tags) --tag $REPOSITORY:$TAG" make buildx
|
|
@ -1,9 +1,7 @@
|
||||||
name: goreleaser
|
name: goreleaser
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
workflow_call:
|
||||||
tags:
|
|
||||||
- "v*" # Versioning tags
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write # Required to upload dist files
|
contents: write # Required to upload dist files
|
||||||
|
@ -29,3 +27,8 @@ jobs:
|
||||||
args: release --rm-dist
|
args: release --rm-dist
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: dist
|
||||||
|
path: ./dist/*
|
|
@ -6,7 +6,7 @@ on:
|
||||||
- latest
|
- latest
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ci-tests-${{ github.ref }}-1
|
group: ci-pull-request-${{ github.ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
name: goreleaser
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [latest]
|
||||||
|
tags: ["v*"]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write # Required to upload dist files
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ci-push-version-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
goreleaser:
|
||||||
|
uses: ./.github/workflows/_goreleaser.yml
|
||||||
|
docker-buildx:
|
||||||
|
needs: goreleaser
|
||||||
|
uses: ./.github/workflows/_docker-buildx.yml
|
|
@ -16,6 +16,7 @@ coverage.*
|
||||||
|
|
||||||
# CI
|
# CI
|
||||||
build/
|
build/
|
||||||
|
dist/
|
||||||
|
|
||||||
# Editors
|
# Editors
|
||||||
*~
|
*~
|
||||||
|
|
|
@ -8,12 +8,24 @@ builds:
|
||||||
- linux
|
- linux
|
||||||
- windows
|
- windows
|
||||||
- darwin
|
- darwin
|
||||||
main: ./cmd/server
|
goarch:
|
||||||
|
- amd64
|
||||||
|
- arm64
|
||||||
|
- arm
|
||||||
|
goarm:
|
||||||
|
- 6
|
||||||
|
- 7
|
||||||
|
ignore:
|
||||||
|
- goos: windows
|
||||||
|
goarch: arm
|
||||||
|
- goos: windows
|
||||||
|
goarch: arm64
|
||||||
|
main: ./cmd/bazaar
|
||||||
|
ldflags:
|
||||||
|
- -s -w
|
||||||
archives:
|
archives:
|
||||||
- replacements:
|
- replacements:
|
||||||
darwin: macos
|
darwin: macos
|
||||||
linux: linux
|
|
||||||
windows: windows
|
|
||||||
386: i386
|
386: i386
|
||||||
amd64: x86_64
|
amd64: x86_64
|
||||||
source:
|
source:
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
# Build stage
|
# Build stage
|
||||||
ARG GOLANG_VERSION
|
|
||||||
ARG ALPINE_VERSION
|
ARG ALPINE_VERSION
|
||||||
|
|
||||||
FROM docker.io/library/golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} AS builder
|
FROM docker.io/library/alpine:${ALPINE_VERSION} AS builder
|
||||||
WORKDIR /src
|
ARG TARGETARCH
|
||||||
COPY . .
|
ARG TARGETOS
|
||||||
RUN apk add --no-cache ca-certificates tzdata make && \
|
ARG TARGETVARIANT
|
||||||
make build
|
COPY dist/bazaar_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}/bazaar /usr/bin/bazaar
|
||||||
|
RUN apk add --no-cache ca-certificates tzdata make
|
||||||
|
|
||||||
# Server image
|
# Server image
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
@ -15,8 +15,9 @@ ENV PORT 8080
|
||||||
LABEL org.opencontainers.image.source="https://github.com/fmartingr/bazaar"
|
LABEL org.opencontainers.image.source="https://github.com/fmartingr/bazaar"
|
||||||
LABEL maintainer="Felipe Martin <github@fmartingr.com>"
|
LABEL maintainer="Felipe Martin <github@fmartingr.com>"
|
||||||
|
|
||||||
COPY --from=builder /src/build/bazaar /usr/bin/
|
COPY --from=builder /usr/bin/bazaar /usr/bin/bazaar
|
||||||
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
||||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
|
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/bin/bazaar"]
|
ENTRYPOINT ["/usr/bin/bazaar"]
|
||||||
|
|
29
Makefile
29
Makefile
|
@ -1,8 +1,5 @@
|
||||||
PROJECT_NAME := bazaar
|
PROJECT_NAME := bazaar
|
||||||
|
|
||||||
GOLANG_VERSION=1.19
|
|
||||||
|
|
||||||
VERSION_COMMIT := $git rev-parse --short HEAD)
|
|
||||||
SOURCE_FILES ?=./internal/... ./cmd/... ./pkg/...
|
SOURCE_FILES ?=./internal/... ./cmd/... ./pkg/...
|
||||||
|
|
||||||
TEST_OPTIONS ?= -v -failfast -race -bench=. -benchtime=100000x -cover -coverprofile=coverage.out
|
TEST_OPTIONS ?= -v -failfast -race -bench=. -benchtime=100000x -cover -coverprofile=coverage.out
|
||||||
|
@ -10,24 +7,20 @@ TEST_TIMEOUT ?=1m
|
||||||
|
|
||||||
CLEAN_OPTIONS ?=-modcache -testcache
|
CLEAN_OPTIONS ?=-modcache -testcache
|
||||||
|
|
||||||
LD_FLAGS := -X main.version=$(VERSION) -s -w
|
|
||||||
CGO_ENABLED := 0
|
CGO_ENABLED := 0
|
||||||
|
|
||||||
BUILDS_PATH := ./build
|
BUILDS_PATH := ./dist
|
||||||
FROM_MAKEFILE := y
|
FROM_MAKEFILE := y
|
||||||
|
|
||||||
CONTAINER_RUNTIME := podman
|
CONTAINER_RUNTIME := podman
|
||||||
CONTAINERFILE_NAME := Containerfile
|
CONTAINERFILE_NAME := Containerfile
|
||||||
CONTAINER_GOLANG_VERSION := ${GOLANG_VERSION}
|
|
||||||
CONTAINER_ALPINE_VERSION := 3.16
|
CONTAINER_ALPINE_VERSION := 3.16
|
||||||
CONTAINER_IMAGE_NAME := fmartingr/${PROJECT_NAME}
|
|
||||||
CONTAINER_IMAGE_TAG := dev
|
BUILDX_PLATFORMS := linux/amd64,arm64,linux/arm/v7
|
||||||
|
|
||||||
# Common exports
|
# Common exports
|
||||||
export FROM_MAKEFILE
|
export FROM_MAKEFILE
|
||||||
export VERSION_COMMIT
|
|
||||||
|
|
||||||
export LD_FLAGS
|
|
||||||
export CGO_ENABLED
|
export CGO_ENABLED
|
||||||
|
|
||||||
export SOURCE_FILES
|
export SOURCE_FILES
|
||||||
|
@ -37,10 +30,9 @@ export BUILDS_PATH
|
||||||
|
|
||||||
export CONTAINER_RUNTIME
|
export CONTAINER_RUNTIME
|
||||||
export CONTAINERFILE_NAME
|
export CONTAINERFILE_NAME
|
||||||
export CONTAINER_GOLANG_VERSION
|
|
||||||
export CONTAINER_ALPINE_VERSION
|
export CONTAINER_ALPINE_VERSION
|
||||||
export CONTAINER_IMAGE_NAME
|
|
||||||
export CONTAINER_IMAGE_TAG
|
export BUILDX_PLATFORMS
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: help
|
all: help
|
||||||
|
@ -67,13 +59,12 @@ clean: ### clean test cache, build files
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build: clean ### builds the project for the setup os/arch combinations
|
build: clean ### builds the project for the setup os/arch combinations
|
||||||
$(info: Make: Build)
|
$(info: Make: Build)
|
||||||
@go build -a -v -ldflags "${LD_FLAGS}" -o ${BUILDS_PATH}/bazaar ./cmd/bazaar/*.go
|
@goreleaser build --rm-dist --snapshot
|
||||||
@chmod +x ${BUILDS_PATH}/bazaar
|
|
||||||
|
|
||||||
.PHONY: build-container-image
|
.PHONY: buildx
|
||||||
build-container:
|
buildx:
|
||||||
$(info: Make: Container image)
|
$(info: Make: Buildx)
|
||||||
@bash scripts/build-container-image.sh
|
@bash scripts/buildx.sh
|
||||||
|
|
||||||
.PHONY: quick-run
|
.PHONY: quick-run
|
||||||
quick-run: ### Executes the project using golang
|
quick-run: ### Executes the project using golang
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [ -z "$FROM_MAKEFILE" ]; then
|
|
||||||
echo "Do not call this file directly - use the make command"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
${CONTAINER_RUNTIME} build --build-arg "GOLANG_VERSION=${CONTAINER_GOLANG_VERSION}" --build-arg="ALPINE_VERSION=${CONTAINER_ALPINE_VERSION}" -t ${CONTAINER_IMAGE_NAME}:${CONTAINER_IMAGE_TAG} -f ${CONTAINERFILE_NAME} .
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -z "$FROM_MAKEFILE" ]; then
|
||||||
|
echo "Do not call this file directly - use the make command"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
CONTAINER_RUNTIME=docker # Forcing docker
|
||||||
|
|
||||||
|
if [ "$CONTAINER_RUNTIME" == "docker" ]; then
|
||||||
|
$CONTAINER_RUNTIME buildx create --use --name bazaar_builder
|
||||||
|
fi
|
||||||
|
|
||||||
|
cp -r dist/bazaar_linux_arm_7 dist/bazaar_linux_armv7
|
||||||
|
cp -r dist/bazaar_linux_amd64_v1 dist/bazaar_linux_amd64
|
||||||
|
|
||||||
|
$CONTAINER_RUNTIME buildx build -f ${CONTAINERFILE_NAME} --platform=${BUILDX_PLATFORMS} --build-arg "ALPINE_VERSION=${CONTAINER_ALPINE_VERSION}" ${CONTAINER_BUILDX_OPTIONS} .
|
||||||
|
|
||||||
|
if [ "$CONTAINER_RUNTIME" == "docker" ]; then
|
||||||
|
$CONTAINER_RUNTIME buildx rm bazaar_builder
|
||||||
|
fi
|
Loading…
Reference in New Issue