fix: enable CGO builds

* debian with CGO build step
* goreleaser binary build
This commit is contained in:
Mohamed Sohail 2022-12-01 09:19:47 +00:00
parent fa0fbd8b85
commit 529f9ab626
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
7 changed files with 78 additions and 18 deletions

3
.env.example Normal file
View File

@ -0,0 +1,3 @@
POSTGRES_DSN=postgres://postgres:postgres@postgres:5432/cic_custodial
REDIS_DSN=redis://redis:6379/1
ASYNQ_DSN=redis://redis:6379/0

View File

@ -1,4 +1,4 @@
name: goreleaser
name: binary_release
on:
push:
@ -8,6 +8,8 @@ on:
jobs:
goreleaser:
runs-on: ubuntu-latest
container:
image: goreleaser/goreleaser-cross
environment: build
steps:
- name: Checkout
@ -30,6 +32,6 @@ jobs:
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: --parallelism 1 --rm-dist --skip-validate
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

29
.github/workflows/docker_release.yaml vendored Normal file
View File

@ -0,0 +1,29 @@
name: docker_release
on:
push:
tags:
- "v*"
jobs:
build-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: docker/login-action@v1.14.1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: docker compose build push
env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
run: |
export TAG=$GITHUB_REF_NAME
docker-compose -f docker-compose.build.yaml build --progress plain
docker-compose -f docker-compose.build.yaml push
export TAG=latest
docker-compose -f docker-compose.build.yaml build --progress plain
docker-compose -f docker-compose.build.yaml push

View File

@ -1,6 +1,9 @@
builds:
- id: linux-amd64
- env:
- CGO_ENABLED=1
- CC=x86_64-linux-gnu-gcc
- CXX=x86_64-linux-gnu-g++
goos:
- linux
goarch:
@ -8,22 +11,10 @@ builds:
main: ./cmd
ldflags:
- -s -w
binary: cic-custodial
archives:
- format: tar.gz
files:
- LICENSE
- config.toml
dockers:
- goos: linux
goarch: amd64
ids:
- cic-custodial
image_templates:
- "ghcr.io/grassrootseconomics/cic-custodial/cic-custodial:latest"
- "ghcr.io/grassrootseconomics/cic-custodial/cic-custodial:{{ .Tag }}"
dockerfile: Dockerfile
extra_files:
- config.toml

View File

@ -1,4 +1,10 @@
FROM debian:11-slim
FROM golang:1.19-bullseye as build
WORKDIR /build
COPY . .
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o cic-custodial -ldflags="-s -w" cmd/*.go
FROM debian:bullseye-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN set -x && \
@ -8,7 +14,7 @@ RUN set -x && \
WORKDIR /service
COPY cic-custodial .
COPY --from=build /build/cic-custodial .
COPY config.toml .
CMD ["./cic-custodial"]

10
docker-compose.build.yaml Normal file
View File

@ -0,0 +1,10 @@
version: '3.9'
services:
cic-custodial:
image: ${IMAGE_BASE_URL:-ghcr.io/grassrootseconomics/cic-custodial}/cic-custodial:${TAG:-latest}
build:
context: .
dockerfile: Dockerfile
cache_from:
- ${IMAGE_BASE_URL:-ghcr.io/grassrootseconomics/cic-custodial}/cic-cache:latest

View File

@ -6,9 +6,15 @@ services:
command: redis-server --loglevel warning
ports:
- '6379:6379'
healthcheck:
test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
interval: 10s
timeout: 5s
retries: 5
postgres:
image: postgres:14-alpine
restart: unless-stopped
user: postgres
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
@ -17,18 +23,31 @@ services:
- cic-custodial:/var/lib/postgresql/data
ports:
- '5432:5432'
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5
asynqmon:
image: hibiken/asynqmon
restart: unless-stopped
ports:
- '8080:8080'
depends_on:
redis:
condition: service_healthy
cic-custodial:
image: ghcr.io/grassrootseconomics/cic-custodial/cic-custodial:latest
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
env_file:
- .env
ports:
- '8080:8080'
- '5000:5000'
volumes:
cic-custodial:
driver: local