Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Sep 28, 2024
1 parent a9d3a58 commit 0e08a1b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 65 deletions.
31 changes: 6 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ jobs:
token: ${{ secrets.NUMARY_GITHUB_TOKEN }}
- run: >
earthly
--ci
--save-inline-cache
--use-inline-cache
--allow-privileged
--secret SPEAKEASY_API_KEY=$SPEAKEASY_API_KEY
--secret GITHUB_TOKEN=$GITHUB_TOKEN
--push
${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }}
+pre-commit
env:
SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }}
GITHUB_TOKEN: ${{ secrets.NUMARY_GITHUB_TOKEN }}
- name: Get changed files
id: changed-files
shell: bash
Expand All @@ -54,29 +58,6 @@ jobs:
exit 1
fi
Tests:
runs-on: "ubuntu-latest"
needs:
- Dirty
steps:
- uses: 'actions/checkout@v4'
with:
fetch-depth: 0
- name: Setup Env
uses: ./.github/actions/env
with:
token: ${{ secrets.NUMARY_GITHUB_TOKEN }}
- run: >
earthly
--no-output
--ci
--allow-privileged
--secret SPEAKEASY_API_KEY=$SPEAKEASY_API_KEY
${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }}
+tests
env:
SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }}
GoReleaser:
runs-on: "ubuntu-latest"
if: contains(github.event.pull_request.labels.*.name, 'build-images') || github.ref == 'refs/heads/main' || github.event_name == 'merge_group'
Expand Down Expand Up @@ -122,7 +103,7 @@ jobs:
environment: staging
needs:
- GoReleaser
- Tests
- Dirty
steps:
- uses: earthly/actions-setup@v1
with:
Expand Down
107 changes: 67 additions & 40 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ IMPORT github.com/formancehq/stack/releases:main AS releases

FROM core+base-image

ARG --global REPOSITORY=ghcr.io

golang-image:
RUN apk update && apk add go
ENV GOPATH=/go
Expand All @@ -16,49 +18,31 @@ golang-image:

RUN go build -v std

SAVE IMAGE --push 192.168.0.83:5555/formancehq/ledger:golang-image
SAVE IMAGE --push ${REPOSITORY}/formancehq/ledger:golang-image

golang-deps:
BUILD +golang-image

FROM +golang-image
WORKDIR /src
COPY main.go go.mod go.sum .
COPY pkg/client/go.* pkg/client/
COPY go.mod go.sum .
RUN go mod download
RUN go get github.com/formancehq/go-libs/...
RUN go install github.com/formancehq/go-libs/...

SAVE ARTIFACT /go
SAVE IMAGE --push 192.168.0.83:5555/formancehq/ledger:deps

SAVE IMAGE --push ${REPOSITORY}/formancehq/ledger:deps

sources:
WORKDIR /src
COPY --dir internal pkg cmd .
COPY --dir internal pkg cmd test .
COPY main.go go.sum go.mod .
SAVE ARTIFACT /src

test-sources:
FROM +sources
COPY --dir test .
SAVE ARTIFACT /src

tidy:
BUILD +golang-image
BUILD +golang-deps
FROM +golang-image
COPY (+golang-deps/go) /go
COPY (+test-sources/src) /src
WORKDIR /src
RUN go mod tidy

SAVE ARTIFACT go.sum
SAVE ARTIFACT go.mod

SAVE IMAGE --push 192.168.0.83:5555/formancehq/ledger:tidy

compile:
BUILD +golang-image
BUILD +golang-deps

FROM +golang-image
COPY (+golang-deps/go) /go
COPY (+sources/src) /src
Expand All @@ -79,12 +63,27 @@ build-image:
ARG tag=latest
DO core+SAVE_IMAGE --COMPONENT=ledger --REPOSITORY=${REPOSITORY} --TAG=$tag

tidy:
BUILD +golang-image
BUILD +golang-deps

FROM +golang-image
COPY (+golang-deps/go) /go
COPY (+sources/src) /src
WORKDIR /src
RUN go mod tidy

SAVE ARTIFACT go.sum
SAVE ARTIFACT go.mod

SAVE IMAGE --push ${REPOSITORY}/formancehq/ledger:tidy

mockgen-image:
FROM +golang-image
RUN apk update && apk add openjdk11 bash curl gcc musl-dev
RUN go install go.uber.org/mock/mockgen@latest

SAVE IMAGE --push 192.168.0.83:5555/formancehq/ledger:mockgen
SAVE IMAGE --push ${REPOSITORY}/formancehq/ledger:mockgen

generate-mocks:
BUILD +mockgen-image
Expand All @@ -97,18 +96,20 @@ generate-mocks:
SAVE ARTIFACT pkg AS LOCAL pkg
SAVE ARTIFACT cmd AS LOCAL cmd

tests-image:
FROM +golang-image
RUN apk update && apk add gcc musl-dev docker jq

SAVE IMAGE --push ${REPOSITORY}/formancehq/ledger:tests

tests:
BUILD +generate-mocks
BUILD +golang-image
BUILD +tests-image
BUILD +golang-deps

FROM +golang-image
RUN apk update && apk add gcc musl-dev
FROM +tests-image

COPY (+golang-deps/go) /go
COPY --dir (+test-sources/src) /src
COPY --dir (+generate-mocks/*) /src/
COPY (+tidy/*) /src
COPY --dir (+sources/src) /src
WORKDIR /src
RUN go install github.com/onsi/ginkgo/v2/ginkgo

Expand Down Expand Up @@ -158,9 +159,20 @@ deploy:
deploy-staging:
BUILD core+deploy-staging

lint-image:
FROM +golang-image
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.61.0

SAVE IMAGE --push ${REPOSITORY}/formancehq/ledger:lint

lint:
FROM +tidy
RUN golangci-lint run --fix --build-tags it --timeout 2m
BUILD +lint-image

FROM +lint-image
COPY (+golang-deps/go) /go
COPY (+sources/src) /src
WORKDIR /src
RUN golangci-lint run --fix --build-tags it --timeout 5m
SAVE ARTIFACT cmd AS LOCAL cmd
SAVE ARTIFACT internal AS LOCAL internal
SAVE ARTIFACT pkg AS LOCAL pkg
Expand All @@ -173,9 +185,7 @@ pre-commit:
BUILD +openapi
BUILD +generate-client
BUILD +export-docs-events
IF [ "$EARTHLY_CI" = "true" ]
BUILD +tests
END
BUILD +tests

bench:
FROM +tidy
Expand Down Expand Up @@ -218,17 +228,32 @@ openapi:
RUN yq -oy ./openapi.json > openapi.yaml
SAVE ARTIFACT ./openapi.yaml AS LOCAL ./openapi.yaml

SAVE IMAGE --push ${REPOSITORY}/formancehq/ledger:openapi

release:
FROM core+builder-image
ARG mode=local
COPY --dir . /src
DO core+GORELEASER --mode=$mode

speakeasy-image:
RUN apk update && apk add yarn jq unzip curl
ARG VERSION=v1.351.0
ARG TARGETARCH
RUN curl -fsSL https://github.com/speakeasy-api/speakeasy/releases/download/${VERSION}/speakeasy_linux_$TARGETARCH.zip -o /tmp/speakeasy_linux_$TARGETARCH.zip
RUN unzip /tmp/speakeasy_linux_$TARGETARCH.zip speakeasy
RUN chmod +x speakeasy
SAVE ARTIFACT speakeasy

SAVE IMAGE --push ${REPOSITORY}/formancehq/ledger:speakeasy

generate-client:
FROM node:20-alpine
BUILD +speakeasy-image
BUILD +openapi

RUN apk update && apk add yq jq
WORKDIR /src
COPY (core+sources-speakeasy/speakeasy) /bin/speakeasy
COPY (+speakeasy-image/speakeasy) /bin/speakeasy
COPY (+openapi/openapi.yaml) openapi.yaml
RUN cat ./openapi.yaml | yq e -o json > openapi.json
COPY (releases+sources/src/openapi-overlay.json) openapi-overlay.json
Expand All @@ -237,6 +262,8 @@ generate-client:
RUN --secret SPEAKEASY_API_KEY speakeasy generate sdk -s ./final.json -o ./client -l go
SAVE ARTIFACT client AS LOCAL ./pkg/client

SAVE IMAGE --push ${REPOSITORY}/formancehq/ledger:sdk

export-database-schema:
BUILD +sources
FROM +sources
Expand Down

0 comments on commit 0e08a1b

Please sign in to comment.