feat: stratt #15
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 image | |
on: | |
push: | |
branches: ["main", "*"] | |
pull_request: | |
# The branches below must be a subset of the branches above | |
branches: ["main"] | |
jobs: | |
prepare: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.finding-files.outputs.FILELIST }} | |
branch: ${{ steps.extract_branch.outputs.branch }} | |
repository: ${{ steps.extract_repo.outputs.repository }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Finding files and store to output | |
id: finding-files | |
run: | | |
echo "FILELIST=$(find . -name 'Containerfile' -print | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT | |
- name: Show files | |
run: echo "${{ steps.finding-files.outputs.FILELIST }}" | |
- name: Extract branch name | |
shell: bash | |
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | |
id: extract_branch | |
- name: Extract repo name | |
shell: bash | |
run: echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT | |
id: extract_repo | |
build-image: | |
runs-on: ubuntu-latest | |
needs: prepare | |
strategy: | |
matrix: | |
manifest: ${{ fromJson(needs.prepare.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Setup Go environment | |
uses: actions/[email protected] | |
- name: Run prepare | |
run: | | |
cd src-template | |
go run main.go | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract folder name | |
shell: bash | |
run: read -ra strarr <<<"${{ matrix.manifest }}" && echo "folder=${strarr[1]}" >> $GITHUB_OUTPUT | |
env: | |
IFS: "/" | |
id: extract_folder | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: | | |
ghcr.io/${{ needs.prepare.outputs.repository }}/${{steps.extract_folder.outputs.folder}}:${{ needs.prepare.outputs.branch }} |