diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e7b9591 --- /dev/null +++ b/.env.example @@ -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 \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/binary_release.yaml similarity index 86% rename from .github/workflows/release.yaml rename to .github/workflows/binary_release.yaml index ec406e9..83dc1ae 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/binary_release.yaml @@ -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 }} diff --git a/.github/workflows/docker_release.yaml b/.github/workflows/docker_release.yaml new file mode 100644 index 0000000..8471fa8 --- /dev/null +++ b/.github/workflows/docker_release.yaml @@ -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 diff --git a/.goreleaser.yaml b/.goreleaser.yaml index a446b14..c1e24ad 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -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 - \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index c8c1ed7..a55be5b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/docker-compose.build.yaml b/docker-compose.build.yaml new file mode 100644 index 0000000..b196969 --- /dev/null +++ b/docker-compose.build.yaml @@ -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 + \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index d23addd..8e5afdd 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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