Skip to content

Commit

Permalink
ci: switched to earthly for ci builds
Browse files Browse the repository at this point in the history
  • Loading branch information
ADRFranklin committed May 11, 2024
1 parent 8738a36 commit 96c2a9d
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 274 deletions.
4 changes: 4 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ FROM ghcr.io/adrfranklin/nodedevcontainer:latest
RUN apk update && apk add -q --update --progress --no-cache curl
# Install Task
RUN sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin && chmod +x /usr/local/bin/task
# Install Earthly
RUN wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly \
&& chmod +x /usr/local/bin/earthly \
&& /usr/local/bin/earthly bootstrap --with-autocomplete
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"yoavbls.pretty-ts-errors",
"BitBelt.converttoasciiart",
"typespec.typespec-vscode",
"rangav.vscode-thunder-client"
"rangav.vscode-thunder-client",
"earthly.earthfile-syntax-highlighting"
],
"settings": {
"files.eol": "\n",
Expand Down
2 changes: 2 additions & 0 deletions .earthlyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
67 changes: 23 additions & 44 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,22 @@ jobs:
build:
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ubuntu-latest
env:
FORCE_COLOR: 1
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Docker Meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/petio-team/petio
tags: |
type=ref,event=pr
type=ref,event=tag
type=sha,format=long
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
type=raw,value=nightly,enable=${{ github.ref == format('refs/heads/{0}', 'dev') }}
type=raw,value=new-ui,enable=${{ github.ref == format('refs/heads/{0}', 'new-ui') }}
type=raw,value=preview,enable=${{ github.ref == format('refs/heads/{0}', 'preview') }}
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- uses: earthly/actions-setup@v1
with:
version: v0.8.0

- name: Login to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
Expand All @@ -38,33 +31,19 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx
- if: ${{ github.ref == format('refs/heads/{0}', 'master') }}
run: echo "IMAGE_LABEL=latest" >> $GITHUB_ENV

- name: Build and Push
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- if: ${{ github.ref == format('refs/heads/{0}', 'dev') }}
run: echo "IMAGE_LABEL=nightly" >> $GITHUB_ENV

- if: ${{ github.ref == format('refs/heads/{0}', 'preview') }}
run: echo "IMAGE_LABEL=staging" >> $GITHUB_ENV

- if: ${{ env.IMAGE_LABEL == '' }}
run: echo "IMAGE_LABEL=$BRANCH_NAME" >> $GITHUB_ENV

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- run: echo "SHORT_SHA=`git rev-parse --short HEAD`" >> $GITHUB_ENV

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Run build
run: earthly --ci --push +build-all COMMIT=$SHORT_SHA LABEL=$IMAGE_LABEL
66 changes: 0 additions & 66 deletions Dockerfile

This file was deleted.

37 changes: 37 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
VERSION 0.8

build-all:
BUILD \
--platform=linux/amd64 \
--platform=linux/arm64 \
+build-image

build:
FROM node:20.11.1-alpine3.19
WORKDIR /build
COPY . .
RUN \
yarn workspaces focus --all && \
yarn workspace frontend run build && \
yarn workspace api run build:prod && \
yarn run pkg && \
# rename x64 to amd64
for f in ./dist/releases/*; do mv "$f" "$(echo "$f" | sed s/x64/amd64/)"; done
SAVE ARTIFACT ./dist/releases

build-image:
ARG TARGETPLATFORM
ARG TARGETARCH
ARG TAG=latest
ARG --required COMMIT
FROM --platform=$TARGETPLATFORM scratch
ENV DATA_DIR=/data
ENV HTTP_ADDR=0.0.0.0
ENV HTTP_PORT=7777
COPY \
--platform=linux/amd64 \
(+build/releases/petio-linuxstatic-$TARGETARCH) ./petio
VOLUME ["/data"]
ENTRYPOINT ["/petio"]
SAVE IMAGE --push ghcr.io/petio-team/petio:$TAG
SAVE IMAGE --push ghcr.io/petio-team/petio:$COMMIT
152 changes: 0 additions & 152 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,160 +5,8 @@ tasks:
cmds:
- task: dev:api

# -
# Run development related tasks
# -
dev:api:
dir: pkg/api
cmds:
- yarn workspace api run watch

dev:fe:
dir: pkg/frontend
cmds:
- yarn workspace frontend run start

dev:adm:
dir: pkg/admin
cmds:
- yarn workspace admin run start

dev:compose:
cmds:
- docker-compose up -d
- docker-compose logs -f petio

# -
# Run app
# -
run:api:
cmds:
- yarn workspace api run start

# -
# Debug/Benchmark/Analysis app
# -
debug:api:
cmds:
- yarn workspace api run clinic

# -
# Run build related tasks
# -
build:
deps: ['build:pre']
cmds:
- task: build:fe
- task: build:api:prod

build:pre:
cmds:
- yarn workspaces focus --all

build:fe:
dir: pkg/frontend
cmds:
- yarn workspace frontend run build

build:api:
dir: pkg/api
cmds:
- yarn workspace api run build

build:api:prod:
dir: pkg/api
cmds:
- yarn workspace api run build:prod

# -
# Generate
# -
generate:
cmds:
- yarn dlx prisma generate

# -
# Package
# -
pkg:
deps:
- 'build:pre'
- 'build:fe'
- 'build:api:prod'
cmds:
- yarn run release

pkg:docker:
dir: pkg/api
cmds:
- pkg --targets node16-alpine-x64 --public-packages "*" --output ../../releases/petio-alpine-x64 ./main.js

# -
# Docker
# -
# Build the image itself
docker:build:
cmds:
- docker build -t {{.DOCKER_IMAGE_REPO}}:local .
env:
DOCKER_BUILDKIT: 1

# Publish the hash of the image
docker:hash:
deps: ['docker:build']
cmds:
- docker tag {{.DOCKER_IMAGE_REPO}}:local {{.DOCKER_IMAGE_REPO}}:{{.DOCKER_IMAGE_REPO_VERSION}}
- docker push {{.DOCKER_IMAGE_REPO}}:{{.DOCKER_IMAGE_REPO_VERSION}}
vars:
DOCKER_IMAGE_REPO_VERSION:
sh: git log -1 --format=%H

# Publish the new-ui image
docker:new-ui:
deps: ['docker:hash']
cmds:
- docker tag {{.DOCKER_IMAGE_REPO}}:local {{.DOCKER_IMAGE_REPO}}:new-ui
- docker push {{.DOCKER_IMAGE_REPO}}:new-ui

# Publish the nightly image
docker:nightly:
deps: ['docker:hash']
cmds:
- docker tag {{.DOCKER_IMAGE_REPO}}:local {{.DOCKER_IMAGE_REPO}}:nightly
- docker push {{.DOCKER_IMAGE_REPO}}:nightly

# Publish the preview image
docker:preview:
deps: ['docker:hash']
cmds:
- docker tag {{.DOCKER_IMAGE_REPO}}:local {{.DOCKER_IMAGE_REPO}}:preview
- docker push {{.DOCKER_IMAGE_REPO}}:preview

# Publish the latest image
docker:latest:
deps: ['docker:hash']
cmds:
- docker tag {{.DOCKER_IMAGE_REPO}}:local {{.DOCKER_IMAGE_REPO}}:latest
- docker push {{.DOCKER_IMAGE_REPO}}:latest

# -
# Release
# -
release:
dir: pkg/api
cmds:
- yarn dlx semantic-release --extends ../../semantic-release.json --dry-run --no-ci

release:prepare:
cmds:
- task: pkg
- task: docker:latest

release:ci:
dir: pkg/api
cmds:
- yarn dlx semantic-release --extends ../../semantic-release.json

# Global Vars
vars:
DOCKER_IMAGE_REPO: ghcr.io/petio-team/petio
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
image: ghcr.io/petio-team/petio:${PETIO_DOCKER_TAG:-latest}
container_name: '${PETIO_DOCKER_CONT_NAME:-petio}'
hostname: ${PETIO_DOCKER_HOSTNAME:-petio}
environment:
- DATABASE_URL=${DATABASE_URL:-mongodb://mongo:27017/petio}
ports:
- '${PETIO_DOCKER_ADDRESS:-127.0.0.1}:${PETIO_DOCKER_PORT:-7777}:7777'
networks:
Expand All @@ -26,6 +28,5 @@ services:
- '${MONGODB_DOCKER_PORT:-27017}:27017'
networks:
- petio-network
user: '${PUID:-1000}:${PGID:-1000}'
volumes:
- ${MONGODB_DATA_VOLUME:-./data/db}:/data/db
Loading

0 comments on commit 96c2a9d

Please sign in to comment.