|
| 1 | +name: Build and publish |
| 2 | +on: |
| 3 | + schedule: |
| 4 | + - cron: "23 3 * * *" |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + |
| 12 | +env: |
| 13 | + # github.repository as <account>/<repo> |
| 14 | + IMAGE_NAME: nfs-server |
| 15 | + IMAGES: | |
| 16 | + docker.io/obebete/nfs-server |
| 17 | + ghcr.io/obeone/nfs-server |
| 18 | +
|
| 19 | +jobs: |
| 20 | + Build: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + packages: write |
| 25 | + # This is used to complete the identity challenge |
| 26 | + # with sigstore/fulcio when running outside of PRs. |
| 27 | + id-token: write |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Login to Docker Hub |
| 31 | + uses: docker/login-action@v2 |
| 32 | + with: |
| 33 | + registry: docker.io |
| 34 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 35 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 36 | + |
| 37 | + - name: Login to GitHub Container Registry |
| 38 | + uses: docker/login-action@v2 |
| 39 | + with: |
| 40 | + registry: ghcr.io |
| 41 | + username: ${{ github.actor }} |
| 42 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + |
| 44 | + - name: Checkout repository |
| 45 | + uses: actions/checkout@v3 |
| 46 | + with: |
| 47 | + fetch-depth: 0 |
| 48 | + |
| 49 | + - name: Install Cosign |
| 50 | + uses: sigstore/cosign-installer@main |
| 51 | + |
| 52 | + - name: Set up QEMU |
| 53 | + uses: docker/setup-qemu-action@v2 |
| 54 | + |
| 55 | + - name: Set up Docker Buildx |
| 56 | + uses: docker/setup-buildx-action@v2 |
| 57 | + |
| 58 | + - name: Finding latest release |
| 59 | + id: version |
| 60 | + uses: pozetroninc/github-action-get-latest-release@master |
| 61 | + with: |
| 62 | + repository: ${{ github.repository }} |
| 63 | + |
| 64 | + - name: Parse semver string |
| 65 | + id: semver_parser |
| 66 | + uses: booxmedialtd/ws-action-parse-semver@v1 |
| 67 | + with: |
| 68 | + input_string: "${{ steps.version.outputs.release }}" |
| 69 | + |
| 70 | + - name: Docker metadata |
| 71 | + id: meta |
| 72 | + uses: docker/metadata-action@v4 |
| 73 | + with: |
| 74 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + images: ${{ env.IMAGES }} |
| 76 | + tags: | |
| 77 | + type=ref,event=branch |
| 78 | + type=ref,event=pr |
| 79 | + type=semver,pattern={{version}},value=${{ steps.version.outputs.version }} |
| 80 | + type=semver,pattern={{major}}.{{minor}},value=${{ steps.version.outputs.version }} |
| 81 | + type=semver,pattern={{major}},value=${{ steps.version.outputs.version }} |
| 82 | + type=semver,pattern=v{{version}},value=${{ steps.version.outputs.version }} |
| 83 | + type=semver,pattern=v{{major}}.{{minor}},value=${{ steps.version.outputs.version }} |
| 84 | + type=semver,pattern=v{{major}},value=${{ steps.version.outputs.version }} |
| 85 | +
|
| 86 | + - name: Build image |
| 87 | + id: build |
| 88 | + uses: docker/build-push-action@v2 |
| 89 | + with: |
| 90 | + context: . |
| 91 | + platforms: | |
| 92 | + linux/amd64 |
| 93 | + linux/arm64 |
| 94 | + linux/i386 |
| 95 | + linux/armhf |
| 96 | + linux/armel |
| 97 | +
|
| 98 | + push: ${{ github.event_name != 'pull_request' }} |
| 99 | + tags: ${{ steps.meta.outputs.tags }} |
| 100 | + labels: ${{ steps.meta.outputs.labels }} |
| 101 | + pull: true |
| 102 | + cache-to: type=gha,mode=max |
| 103 | + cache-from: |
| 104 | + type=gha,mode=maxs.semver_parser.outputs.major }}.${{ steps.semver_parser.outputs.minor }}.${{ steps.semver_parser.outputs.patch }} |
| 105 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest |
| 106 | + |
| 107 | + - name: Sign the images with GitHub OIDC Token |
| 108 | + run: | |
| 109 | + set -e |
| 110 | + for image in "${IMAGES}"; do |
| 111 | + yes | cosign sign ${image}@${DIGEST} |
| 112 | + done |
| 113 | + env: |
| 114 | + TAGS: ${{ steps.build.outputs.tags }} |
| 115 | + DIGEST: ${{ steps.build.outputs.digest }} |
| 116 | + COSIGN_EXPERIMENTAL: true |
| 117 | + if: github.event_name != 'pull_request' |
0 commit comments