feat: create nginx image MAI-1019 MAI-953 #319
Workflow file for this run
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: Check dockerfile | |
on: | |
pull_request: | |
branches: | |
- master | |
paths: | |
- images/** | |
jobs: | |
find-changed-files: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Get specific changed files | |
id: changed-files-docker | |
uses: tj-actions/changed-files@v23 | |
with: | |
files: | | |
images/**/Dockerfile | |
files_ignore: | | |
*.md | |
- name: Set matrix for lint | |
id: set-matrix | |
run: | | |
# See https://stackoverflow.com/a/62953566/11948346 | |
JSON="{\"include\":[" | |
# Loop by lines | |
for path in ${{ steps.changed-files-docker.outputs.all_changed_files }}; do | |
path=$(dirname "$path") | |
# Add path to Dockerfile to the matrix only if it is not already included | |
JSONline="{\"dockerfile\": \"$path\"}," | |
if [[ "$JSON" != *"$JSONline"* ]]; then | |
JSON="$JSON$JSONline" | |
fi | |
done | |
# Remove last "," and add closing brackets | |
if [[ $JSON == *, ]]; then | |
JSON="${JSON%?}" | |
fi | |
JSON="$JSON]}" | |
echo $JSON | |
# Set output | |
echo "::set-output name=matrix::$( echo "$JSON" )" | |
correct-path: | |
needs: find-changed-files | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: true | |
matrix: ${{fromJson(needs.find-changed-files.outputs.matrix)}} | |
steps: | |
- name: Correct name of image | |
run: | | |
NAME=$(basename "$(dirname "${{ matrix.dockerfile }}")") | |
if [[ "$NAME" == "images" ]]; then | |
exit 1 | |
fi | |
- name: Correct tag of image | |
run: | | |
TAG=$(basename "${{ matrix.dockerfile }}") | |
if ! [[ "$TAG" =~ [0-9] ]]; then | |
exit 1 | |
fi | |
hadolint: | |
needs: find-changed-files | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: ${{fromJson(needs.find-changed-files.outputs.matrix)}} | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
- uses: hadolint/hadolint-action@v2.0.0 | |
id: hadolint | |
with: | |
no-color: false | |
dockerfile: ${{ matrix.dockerfile }}/Dockerfile | |
ignore: DL3008 | |
build-image: | |
needs: find-changed-files | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: ${{fromJson(needs.find-changed-files.outputs.matrix)}} | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build | |
uses: docker/build-push-action@v3 | |
with: | |
context: ${{ matrix.dockerfile }} | |
push: false | |
builder: ${{ steps.buildx.outputs.name }} | |
tags: test:${{ github.sha }} |