Build, test and publish Docker Image #62
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build, test and publish Docker Image | |
env: | |
OWNER: ${{ github.repository_owner }} | |
IMAGE_NAME: ${{ github.event.repository.name }} | |
# For more details on events that trigger workflows see: | |
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows | |
on: | |
schedule: | |
# Weekly, at 07:00 on Monday UTC time | |
- cron: "0 7 * * 1" | |
pull_request: | |
paths: | |
- ".github/workflows/docker.yml" | |
- "image/**" | |
- "tests/**" | |
- "requirements-dev.txt" | |
push: | |
branches: | |
- main | |
paths: | |
- ".github/workflows/docker.yml" | |
- "image/**" | |
- "tests/**" | |
- "requirements-dev.txt" | |
workflow_dispatch: | |
# https://docs.github.com/en/actions/using-jobs/using-concurrency | |
concurrency: | |
# only cancel in-progress jobs or runs for the current workflow - matches against branch & tags | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build-test-publish-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout Repo ⚡️ | |
uses: actions/checkout@v4 | |
- name: Set Up Python 🐍 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.x | |
- name: Install Dev Dependencies 📦 | |
run: | | |
pip install --upgrade pip | |
pip install --upgrade -r requirements-dev.txt | |
- name: Get commit sha, this will be used as a tag later on 🏷 | |
shell: bash | |
run: | | |
echo "sha12=$(echo ${GITHUB_SHA} | cut -c1-12)" >> $GITHUB_OUTPUT | |
id: get_sha | |
- name: Build image 🛠 | |
run: docker build --rm --force-rm --tag ${{ env.OWNER }}/${{ env.IMAGE_NAME }}:latest --tag ${{ env.OWNER }}/${{ env.IMAGE_NAME }}:${{steps.get_sha.outputs.sha12}} image/ | |
env: | |
DOCKER_BUILDKIT: 1 | |
# Full logs for CI build | |
BUILDKIT_PROGRESS: plain | |
- name: Run tests ✅ | |
run: python3 -m tests.run_tests --short-image-name ${{ env.IMAGE_NAME }} --owner ${{ env.OWNER }} | |
- name: Login to Docker Hub 🔐 | |
if: github.ref == 'refs/heads/main' || github.event_name == 'schedule' | |
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 | |
with: | |
username: ${{ env.OWNER }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Push Image to Docker Hub 📤 | |
if: github.ref == 'refs/heads/main' || github.event_name == 'schedule' | |
run: docker push --all-tags ${{ env.OWNER }}/${{ env.IMAGE_NAME }} |