Skip to content

Commit

Permalink
[GEN-1164] add workflow to build docker image and push it to ghcr (#556)
Browse files Browse the repository at this point in the history
* add build container step to ci workflow

* Disable provenance to avoid caching manifest

* build docker image when it is not a  pull request, and make push event on main, develop and feature branches
  • Loading branch information
danlu1 authored Apr 4, 2024
1 parent c479c8d commit 950ced4
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ name: build

on:
push:
branches:
- develop
branches: [main, develop, 'GEN*', 'gen*']

pull_request:

release:
types:
- created

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:

test:
Expand Down Expand Up @@ -77,3 +80,51 @@ jobs:
run: python -m build
- name: Publish to pypi
uses: pypa/gh-action-pypi-publish@release/v1


build-container:
needs: [test, lint]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Format tags as registry refs
id: registry_refs
env:
TAGS: ${{ steps.meta.outputs.json }}
run: |
echo tags=$(echo $TAGS | jq '.tags[] | "type=registry,ref=" + . + "_cache"| @text') >> $GITHUB_OUTPUT
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
if: github.event_name != 'pull_request'
with:
context: .
push: true
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: ${{ steps.registry_refs.outputs.tags }},mode=max
cache-to: ${{ steps.registry_refs.outputs.tags }},mode=max

0 comments on commit 950ced4

Please sign in to comment.