Update Dockerfile #163
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: push container to ghcr.io | |
on: | |
push: | |
paths: | |
- '**/Dockerfile' | |
jobs: | |
get-container-names: | |
runs-on: ubuntu-latest # windows-latest | macos-latest | |
name: Get container name | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit. | |
- name: Get changed files | |
id: changed-files | |
uses: tj-actions/[email protected] | |
- name: Get container names | |
id: set-matrix | |
run: | | |
JSON="{\"include\":[" | |
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do | |
if [[ $file == *"Dockerfile"* ]]; then | |
name=${file%/Dockerfile} | |
name=${name#*/} | |
add_string="{\"container-name\": \"$name\"}," | |
if [[ "$JSON" != *"$add_string"* ]]; then | |
JSON="$JSON$add_string" | |
fi | |
fi | |
done | |
if [[ $JSON == *, ]]; then | |
JSON="${JSON%?}" | |
fi | |
JSON="$JSON]}" | |
echo "::set-output name=matrix::$( echo "$JSON" )" | |
push-docker-image: | |
needs: get-container-names | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJSON(needs.get-container-names.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set date tag for the image | |
id: date | |
run: echo "DATE=$(date +'%y%m%d')" >> $GITHUB_ENV | |
- name: Build and Push Docker image | |
run: | | |
docker build ./${{ matrix.container-name }} --tag ghcr.io/dhslab/${{ matrix.container-name }}:$DATE | |
docker tag ghcr.io/dhslab/${{ matrix.container-name }}:$DATE ghcr.io/dhslab/${{ matrix.container-name }}:latest | |
docker push ghcr.io/dhslab/${{ matrix.container-name }}:$DATE | |
docker push ghcr.io/dhslab/${{ matrix.container-name }}:latest |