triger ci/cd #3
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 docker images | |
on: | |
push: | |
paths: | |
- 'deepmod2/**' | |
- 'deepmod2-gpu/**' | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
app: | |
- deepmod2 | |
- deepmod2-gpu | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Read version file | |
id: get_version | |
run: | | |
VERSION=$(cat ${{ matrix.app }}/version) | |
echo "::set-output name=version::$VERSION" | |
- name: Check if files changed | |
id: files_changed | |
run: | | |
if git diff-tree --no-commit-id --name-only -r HEAD | grep "^${{ matrix.app }}/"; then | |
echo "::set-output name=changed::true" | |
else | |
echo "::set-output name=changed::false" | |
fi | |
- name: Build and push Docker image | |
if: ${{ steps.files_changed.outputs.changed == 'true' }} | |
run: | | |
cd ${{ matrix.app }} | |
docker build --build-arg="BUILD_VERSION=${{ steps.get_version.outputs.version }}" -t ghcr.io/${{ github.repository_owner }}/${{ matrix.app }}:${{ steps.get_version.outputs.version }} . | |
docker push ghcr.io/${{ github.repository_owner }}/${{ matrix.app }}:${{ steps.get_version.outputs.version }} | |