Skip to content

Commit

Permalink
feat: add earthly
Browse files Browse the repository at this point in the history
  • Loading branch information
fredleger committed Nov 22, 2023
1 parent e45a33a commit edbb6f1
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 19 deletions.
2 changes: 0 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
virtualenv
README.md
_CI.md
docker-compose*.yaml
docker-compose*.yml
docker/data/**
Conduit.postman_collection.json
51 changes: 51 additions & 0 deletions .github/workflows/earthly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# .github/workflows/ci.yml

name: CI

on:
push:
branches:
- ci/earthly

jobs:
build:
runs-on: ubuntu-latest
env:
FORCE_COLOR: 1

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}

- name: Install asdf
uses: asdf-vm/actions/[email protected]

- name: Install asdf plugins & packages
run: |
asdf plugin add earthly https://github.com/YR-ZR0/asdf-earthly
asdf plugin update --all
asdf install
- name: Put back the git branch into git (Earthly uses it for tagging)
run: |
branch=""
if [ -n "$GITHUB_HEAD_REF" ]; then
branch="$GITHUB_HEAD_REF"
else
branch="${GITHUB_REF##*/}"
fi
git checkout -b "$branch" || true
- name: Earthly version
run: earthly --version

- name: Run build
run: make ci
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
earthly 0.7.21
44 changes: 44 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
VERSION 0.7
FROM earthly/dind:alpine-3.18-docker-23.0.6-r4
WORKDIR /app

deps:
FROM DOCKERFILE --target "base" .

dev:
FROM DOCKERFILE --target "dev" .

prod:
FROM DOCKERFILE --target "prod" .

lint:
FROM +dev
RUN bash scripts/lint.sh

format:
FROM +dev
RUN bash scripts/format.sh

# FIXME: we don't mount .git files in containers, so this doesn't work
# pre-commit:
# FROM +dev
# RUN bash scripts/pre-commit.sh

unit-tests:
FROM +dev
RUN bash scripts/unit-tests.sh

coverage:
FROM +dev
RUN bash scripts/coverage.sh

functional-tests:
FROM +dev
COPY docker-compose.yaml .
WITH DOCKER \
--compose docker-compose.yaml \
--load webofmars/cicdparadox:earthly-latest=+prod \
--load webofmars/cicdparadox:earthly-develop=+dev \
--service mongo --service api
RUN bash scripts/functional-tests.sh
END
25 changes: 13 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,35 @@ ci: lint format unit-tests coverage functional-tests ci-clean
publish: docker-publish

lint:
bash scripts/lint.sh
earthly +lint

format:
bash scripts/format.sh
earthly +format

pre-commit:
bash scripts/pre-commit.sh
# FIXME: since we don't mount .git folders in docker, we can't use pre-commit
# pre-commit:
# earthly +pre-commit

unit-tests:
bash scripts/unit-tests.sh
earthly +unit-tests

coverage:
bash scripts/coverage.sh
earthly +coverage

functional-tests:
bash scripts/functional-tests.sh
earthly --allow-privileged +functional-tests

ci-clean:
rm -rf .pytest_cache
rm -rf .mypy_cache
earthly prune

docker-build: docker-build-prod docker-build-dev

docker-build-prod:
docker build -t webofmars/cicdparadox:standard-latest --target=prod .
earthly +prod

docker-build-dev:
docker build -t webofmars/cicdparadox:standard-develop --target=dev .
earthly +dev

docker-publish: docker-build
docker push webofmars/cicdparadox:standard-latest
earthly prod --push
earthly dev --push
3 changes: 1 addition & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
services:

api:
image: webofmars/cicdparadox:standard-latest
image: webofmars/cicdparadox:earthly-latest
ports:
- "8000:8000"
environment:
Expand Down
3 changes: 0 additions & 3 deletions scripts/functional-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

set -e

echo "Starting API stack"
docker compose up -d api
echo "Waiting for API container to be up"
bash scripts/wait-for-it.sh localhost:8000 --timeout=60 --strict -- echo "API is up"
echo "Waiting for API to be healthy"
Expand All @@ -15,4 +13,3 @@ echo ""
echo "API is healthy"
echo "Running functional tests"
bash scripts/test.sh
docker compose stop

0 comments on commit edbb6f1

Please sign in to comment.