Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI for building package #6

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Run test

on:
push:
branches:
- develop
- feat/*
pull_request:

jobs:
test:
name: 🚴 Test 🚴
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@main

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: github.event_name == 'push'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: 🐳 Prepare Docker
id: prep
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}
PUSH_DOCKER_IMAGE: ${{ inputs.push_docker_image }}
run: |
BRANCH_NAME=$(echo $GITHUB_REF_NAME | sed 's|:|-|' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g' | cut -c1-100 | sed 's/-*$//')

# XXX: Check if there is a slash in the BRANCH_NAME eg: project/add-docker
if [[ "$BRANCH_NAME" == *"/"* ]]; then
# XXX: Change the docker image package to -beta
IMAGE_NAME="$IMAGE_NAME-beta"
TAG="$(echo "$BRANCH_NAME" | sed 's|/|-|g').$(echo $GITHUB_SHA | head -c7)"
else
TAG="$BRANCH_NAME.$(echo $GITHUB_SHA | head -c7)"
fi

echo "tagged_image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "tagged_image=${IMAGE_NAME}:${TAG}" >> $GITHUB_OUTPUT
echo "push_docker_image=$PUSH_DOCKER_IMAGE" >> $GITHUB_OUTPUT
echo "::notice::Tagged docker image: ${IMAGE_NAME}:${TAG}"

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

- name: 🐳 Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.ref }}
restore-keys: |
${{ runner.os }}-buildx-refs/develop
${{ runner.os }}-buildx-

- name: 🐳 Build image
uses: docker/build-push-action@v6
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
file: Dockerfile
push: ${{ steps.prep.outputs.push_docker_image == 'true' }}
load: true
tags: ${{ steps.prep.outputs.tagged_image }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

- name: 🐳 Docker push
if: github.event_name == 'push'
uses: docker/build-push-action@v6
with:
tags: ${{ steps.prep.outputs.tagged_image }}
push: true

- name: 🐳 Move docker cache (🧙 Hack fix)
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM python:3.12-slim-bullseye

LABEL maintainer="TC Developers"
LABEL org.opencontainers.image.source="https://github.com/toggle-corp/embedding-models"

ENV PYTHONUNBUFFERED 1

Check warning on line 6 in Dockerfile

View workflow job for this annotation

GitHub Actions / 🚴 Test 🚴

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

Check warning on line 6 in Dockerfile

View workflow job for this annotation

GitHub Actions / 🚴 Test 🚴

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

Check warning on line 6 in Dockerfile

View workflow job for this annotation

GitHub Actions / 🚴 Test 🚴

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

WORKDIR /code

Expand Down
Loading