Created CI/CD Actions #14
This file contains hidden or 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 | |
| on: | |
| release: | |
| types: [published, edited] | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| RAW_TAG: ${{ github.event.release.tag_name || 'latest'}} | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Derive image tags | |
| id: tags | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | |
| IMAGE=$(echo "$IMAGE" | tr '[:upper:]' '[:lower:]') | |
| CLEAN_TAG="${RAW_TAG#v}" | |
| echo "clean_tag=${CLEAN_TAG}" >> $GITHUB_OUTPUT | |
| echo "image -> $IMAGE" | |
| echo "cicd tag -> ${CLEAN_TAG}" | |
| if [[ -z "$CLEAN_TAG" || "$CLEAN_TAG" == "latest" ]]; then | |
| BASE_TAGS="${IMAGE}:latest" | |
| EOS_TAGS="${IMAGE}:latest-eos" | |
| else | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "${CLEAN_TAG}.0.0" | |
| MAJOR=${MAJOR:-0} | |
| MINOR=${MINOR:-0} | |
| PATCH=${PATCH:-0} | |
| BASE_TAGS="${IMAGE}:${MAJOR} ${IMAGE}:${MAJOR}.${MINOR} ${IMAGE}:${MAJOR}.${MINOR}.${PATCH}" | |
| EOS_TAGS="${IMAGE}:${MAJOR}-eos ${IMAGE}:${MAJOR}.${MINOR}-eos ${IMAGE}:${MAJOR}.${MINOR}.${PATCH}-eos" | |
| fi | |
| echo "image=${IMAGE}" >> "$GITHUB_OUTPUT" | |
| echo "base_tags=$BASE_TAGS" >> "$GITHUB_OUTPUT" | |
| echo "eos_tags=$EOS_TAGS" >> "$GITHUB_OUTPUT" | |
| echo "image tags -> $BASE_TAGS" | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build & Push eos | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./eos.Dockerfile | |
| push: true | |
| tags: ${{ steps.tags.outputs.eos_tags }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| platforms: linux/amd64 | |
| - name: Build & Push base | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: ${{ steps.tags.outputs.base_tags }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| platforms: linux/amd64 |