Publish Image to Docker Hub #59
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: Publish Image to Docker Hub | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [ "main" ] | |
| schedule: | |
| - cron: '0 0 * * 0' | |
| jobs: | |
| pkl-release: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| exists: ${{ steps.apple_pkl.outputs.exists }} | |
| version: ${{ steps.apple_pkl.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Get latest version | |
| id: apple_pkl | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| latest_version=$(curl https://api.github.com/repos/apple/pkl/releases/latest | jq -r '.name') | |
| if gh release view "v$latest_version" --repo "$REPO" > /dev/null 2>&1; then | |
| release_exists=true | |
| else | |
| release_exists=false | |
| fi | |
| echo "version=$latest_version" >> $GITHUB_OUTPUT | |
| echo "exists=$release_exists" >> $GITHUB_OUTPUT | |
| docker-build-and-publish: | |
| runs-on: ubuntu-latest | |
| needs: pkl-release | |
| if: ${{ needs.pkl-release.outputs.exists == 'false' }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Get pkl | |
| env: | |
| VERSION: ${{ needs.pkl-release.outputs.version }} | |
| run: | | |
| curl -L -o ./pkl-linux-amd64 https://github.com/apple/pkl/releases/download/${VERSION}/pkl-linux-amd64 | |
| curl -L -o ./pkl-linux-aarch64 https://github.com/apple/pkl/releases/download/${VERSION}/pkl-linux-aarch64 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: arm64,arm | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Docker Meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: jesscarlos/pkl-cli | |
| tags: | | |
| type=raw,value=latest | |
| type=semver,pattern={{version}},value=${{ needs.pkl-release.outputs.version }} | |
| labels: | | |
| maintainer=Jess Carlos | |
| org.opencontainers.image.title=PKL-CLI | |
| org.opencontainers.image.description=Configuration that is Programmable, Scalable, and Safe | |
| org.opencontainers.image.vendor=Ignittion, LLC. | |
| org.opencontainers.image.version=${{ needs.pkl-release.outputs.version }} | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and Push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| build-args: | | |
| VERSION=${{ needs.pkl-release.outputs.version }} | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| - name: Create GitHub Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| VERSION: ${{ needs.pkl-release.outputs.version }} | |
| run: | | |
| gh release create "v$VERSION" \ | |
| --title="Release $VERSION" \ | |
| --draft=false \ | |
| --prerelease=false | |
| echo "Release $VERSION created successfully." |