docker from personal egazzarr #35
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: Docker automatic build and publish when changes in container dir | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
env: | |
REGISTRY: ghcr.io | |
jobs: | |
build-matrix-from-changed-dirs: | |
runs-on: ubuntu-latest | |
name: Build matrix from directories with changed files | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 # "0" (OR "2" -> To retrieve the preceding commit). | |
- name: Run changed-files with dir_names | |
id: changed-files | |
uses: tj-actions/changed-files@v37 | |
with: | |
files_ignore: | | |
.github/** | |
infrastructure/** | |
.gitignore | |
*.md | |
*.png | |
LICENSE | |
**/README.md | |
dir_names: "true" | |
dir_names_exclude_current_dir: "true" | |
- name: List all changed dirs | |
id: format-output | |
run: | | |
containers=() | |
for dir in ${{ steps.changed-files.outputs.all_changed_files }}; do | |
echo "$dir was changed" | |
tmp_dir=$(echo $dir | cut -d'/' -f2) | |
containers+=("\"${tmp_dir}\"") | |
done | |
CONT_LIST=`echo "[${containers[@]}]" | sed 's/ /,/g'` | |
echo "Updated containers list: $CONT_LIST" | |
echo ::set-output name=container_list::$CONT_LIST | |
outputs: | |
modified_containers: ${{ steps.format-output.outputs.container_list }} | |
build-and-push-modified-containers: | |
needs: build-matrix-from-changed-dirs | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
containers: ${{ fromJSON(needs.build-matrix-from-changed-dirs.outputs.modified_containers) }} | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Docker Checkout | |
uses: actions/checkout@v4 | |
- name: Format tag | |
id: format-tag | |
run: | | |
git clone https://github.com/vre-hub/vre.git | |
cd vre | |
echo "describe_tag is $(git describe --tags | sed 's/-g/-/g')" | |
describe_tag=$(git describe --tags | sed 's/-g/-/g') | |
echo "latest_tag is $(git describe --tags --abbrev=0)" | |
latest_tag=$(git describe --tags --abbrev=0) | |
echo "DESCRIBE_TAG=${describe_tag}" >> $GITHUB_ENV | |
echo "LATEST_TAG=${latest_tag}" >> $GITHUB_ENV | |
- name: Check env output | |
run: | | |
echo "latest_version" is ${{ env.LATEST_TAG }} | |
echo "describe_tag" is ${{ env.DESCRIBE_TAG }} | |
# - name: Action for git describe | |
# id: ghd | |
# uses: proudust/[email protected] | |
- name: Log in to the GH Container Registry | |
id: login | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata for ${{ matrix.containers }} | |
id: metadata | |
uses: docker/[email protected] | |
with: | |
flavor: | | |
latest=true | |
tags: | | |
type=raw,value=${{ env.DESCRIBE_TAG }} | |
# ghcr.io/vre-hub/{vre}-{container_name}:{tag} | |
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ github.event.repository.name }}-${{ matrix.containers }} | |
- name: Build and push ${{ matrix.containers }} | |
id: build | |
uses: docker/[email protected] | |
with: | |
context: containers/${{ matrix.containers }} | |
file: containers/${{ matrix.containers }}/Dockerfile | |
push: true | |
tags: ${{ steps.metadata.outputs.tags }} | |
labels: ${{ steps.metadata.outputs.labels }} | |
build-args: | | |
BUILD_DATE=$(date +'%Y-%m-%dT%H:%M:%SZ') | |
TAG=${{ env.LATEST_TAG }} |