contrib docs update #113
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 and Publish Docker Image | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| container_version: | |
| description: "SemVer version to build (e.g., 1.2.3 or 1.2.3-beta)" | |
| required: true | |
| photon_version: | |
| description: "Photon version (optional - will read from .last_release if not provided)" | |
| required: false | |
| release: | |
| types: [published] | |
| push: | |
| branches: | |
| - dev | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.ref }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - 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 version information | |
| id: version_info | |
| run: | | |
| if [ -f ".last_release" ]; then | |
| PHOTON_VERSION=$(cat .last_release | tr -d '[:space:]') | |
| if [[ -z "$PHOTON_VERSION" || ! "$PHOTON_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Error: .last_release is missing, empty, or contains an invalid version: '$PHOTON_VERSION'" | |
| exit 1 | |
| fi | |
| echo "Read photon version from .last_release: $PHOTON_VERSION" | |
| else | |
| PHOTON_VERSION="${{ github.event.inputs.photon_version }}" | |
| if [[ -z "$PHOTON_VERSION" ]]; then | |
| echo "Error: PHOTON_VERSION must be provided when .last_release file is missing" | |
| exit 1 | |
| fi | |
| fi | |
| if [ "${{ github.event_name }}" == "release" ]; then | |
| CONTAINER_VERSION="${{ github.event.release.tag_name }}" | |
| CONTAINER_VERSION="${CONTAINER_VERSION#v}" | |
| IS_PRERELEASE="${{ github.event.release.prerelease }}" | |
| elif [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref }}" == "refs/heads/dev" ]; then | |
| SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) | |
| CONTAINER_VERSION="dev-${SHORT_SHA}" | |
| IS_PRERELEASE="true" | |
| elif [ "${{ github.event_name }}" == "pull_request" ]; then | |
| CONTAINER_VERSION="pr-${{ github.event.pull_request.number }}" | |
| IS_PRERELEASE="true" | |
| else | |
| CONTAINER_VERSION="${{ github.event.inputs.container_version }}" | |
| CONTAINER_VERSION="${CONTAINER_VERSION#v}" | |
| if [[ "$CONTAINER_VERSION" == *"-beta"* ]]; then | |
| IS_PRERELEASE="true" | |
| else | |
| IS_PRERELEASE="false" | |
| fi | |
| fi | |
| echo "CONTAINER_VERSION=$CONTAINER_VERSION" >> "$GITHUB_ENV" | |
| echo "PHOTON_VERSION=$PHOTON_VERSION" >> "$GITHUB_ENV" | |
| echo "IS_PRERELEASE=$IS_PRERELEASE" >> "$GITHUB_ENV" | |
| echo "Container Version: $CONTAINER_VERSION" | |
| echo "Photon Version: $PHOTON_VERSION" | |
| echo "Is Prerelease: $IS_PRERELEASE" | |
| - name: Generate Docker tags with semver support | |
| id: generate_tags | |
| run: | | |
| CONTAINER_VERSION="${{ env.CONTAINER_VERSION }}" | |
| IS_PRERELEASE="${{ env.IS_PRERELEASE }}" | |
| REPO_NAME="${{ github.repository }}" | |
| DOCKERHUB_REPO="${REPO_NAME,,}" | |
| GHCR_REPO="ghcr.io/${REPO_NAME,,}" | |
| TAGS="$DOCKERHUB_REPO:$CONTAINER_VERSION,$GHCR_REPO:$CONTAINER_VERSION" | |
| if [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref }}" == "refs/heads/dev" ]; then | |
| TAGS="$TAGS,$DOCKERHUB_REPO:dev,$GHCR_REPO:dev" | |
| elif [ "$IS_PRERELEASE" == "true" ]; then | |
| TAGS="$TAGS,$DOCKERHUB_REPO:beta,$GHCR_REPO:beta" | |
| else | |
| if [[ "$CONTAINER_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then | |
| MAJOR="${BASH_REMATCH[1]}" | |
| MINOR="${BASH_REMATCH[2]}" | |
| PATCH="${BASH_REMATCH[3]}" | |
| TAGS="$TAGS,$DOCKERHUB_REPO:$MAJOR,$GHCR_REPO:$MAJOR" | |
| TAGS="$TAGS,$DOCKERHUB_REPO:$MAJOR.$MINOR,$GHCR_REPO:$MAJOR.$MINOR" | |
| TAGS="$TAGS,$DOCKERHUB_REPO:$MAJOR.$MINOR.$PATCH,$GHCR_REPO:$MAJOR.$MINOR.$PATCH" | |
| TAGS="$TAGS,$DOCKERHUB_REPO:latest,$GHCR_REPO:latest" | |
| echo "Generated semver tags for version $MAJOR.$MINOR.$PATCH" | |
| else | |
| echo "Version doesn't match semver pattern, skipping semver tags" | |
| TAGS="$TAGS,$DOCKERHUB_REPO:latest,$GHCR_REPO:latest" | |
| fi | |
| fi | |
| echo "DOCKER_TAGS=$TAGS" >> "$GITHUB_ENV" | |
| echo "Generated tags: $TAGS" | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| build-args: | | |
| PHOTON_VERSION=${{ env.PHOTON_VERSION }} | |
| push: true | |
| tags: ${{ env.DOCKER_TAGS }} | |
| platforms: linux/amd64,linux/arm64 | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Output summary | |
| run: | | |
| echo "## Docker Build Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Event:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Container Version:** ${{ env.CONTAINER_VERSION }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Photon Version:** ${{ env.PHOTON_VERSION }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Is Prerelease:** ${{ env.IS_PRERELEASE }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Tags:** ${{ env.DOCKER_TAGS }}" >> $GITHUB_STEP_SUMMARY |