|
1 | 1 | name: Push to GitHub Registry |
2 | | -on: |
3 | | - push: |
4 | | - branches: |
5 | | - - develop |
6 | 2 |
|
7 | 3 | env: |
8 | | - REGISTRY: ghcr.io |
9 | 4 | IMAGE_NAME: ${{ github.repository }} |
| 5 | + repo-name: ${{ github.repository }} |
10 | 6 |
|
11 | | -jobs: |
12 | | - build: |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: [ develop ] |
| 10 | + workflow_dispatch: |
13 | 11 |
|
| 12 | +jobs: |
| 13 | + build_push_test: |
14 | 14 | runs-on: ubuntu-latest |
15 | | - |
16 | 15 | steps: |
17 | | - - name: Checkout repository |
18 | | - uses: actions/checkout@v4 |
| 16 | + - name: checkout |
| 17 | + uses: actions/checkout@v2 |
19 | 18 |
|
20 | | - # Install the cosign tool except on PR |
21 | | - # https://github.com/sigstore/cosign-installer |
22 | | - - name: Install cosign |
23 | | - if: github.event_name != 'pull_request' |
24 | | - uses: sigstore/cosign-installer@v3 #v3.5.0 |
| 19 | + - name: Login to GitHub Container Registry |
| 20 | + uses: docker/login-action@v1 |
25 | 21 | with: |
26 | | - cosign-release: 'v2.2.4' |
27 | | - |
28 | | - # Set up BuildKit Docker container builder to be able to build |
29 | | - # multi-platform images and export cache |
30 | | - # https://github.com/docker/setup-buildx-action |
31 | | - - name: Set up Docker Buildx |
32 | | - uses: docker/setup-buildx-action@v3 # v3.0.0 |
33 | | - |
34 | | - # Login against a Docker registry except on PR |
35 | | - # https://github.com/docker/login-action |
36 | | - - name: Log into registry ${{ env.REGISTRY }} |
37 | | - if: github.event_name != 'pull_request' |
38 | | - uses: docker/login-action@v3 # v3.0.0 |
39 | | - with: |
40 | | - registry: ${{ env.REGISTRY }} |
| 22 | + registry: ghcr.io |
41 | 23 | username: ${{ github.actor }} |
42 | 24 | password: ${{ secrets.GITHUB_TOKEN }} |
43 | 25 |
|
44 | | - # Extract metadata (tags, labels) for Docker |
45 | | - # https://github.com/docker/metadata-action |
46 | | - - name: Extract Docker metadata |
47 | | - id: meta |
48 | | - uses: docker/metadata-action@v5 # v5.0.0 |
49 | | - with: |
50 | | - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 26 | + - name: Declare some variables |
| 27 | + id: vars |
| 28 | + shell: bash |
| 29 | + run: | |
| 30 | + echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" |
51 | 31 |
|
52 | | - # Build and push Docker image with Buildx (don't push on PR) |
53 | | - # https://github.com/docker/build-push-action |
54 | | - - name: Build and push Docker image |
55 | | - id: build-and-push |
56 | | - uses: docker/build-push-action@v6 # v5.0.0 |
57 | | - with: |
58 | | - context: . |
59 | | - push: ${{ github.event_name != 'pull_request' }} |
60 | | - tags: ${{ steps.meta.outputs.tags }} |
61 | | - labels: ${{ steps.meta.outputs.labels }} |
62 | | - cache-from: type=gha |
63 | | - cache-to: type=gha,mode=max |
| 32 | + - name: Build |
| 33 | + run: docker build -t ${{ github.repository_owner }}/${{ env.IMAGE_NAME }} . |
| 34 | + |
| 35 | + - name: Tag (Latest) |
| 36 | + run: docker tag ${{ github.repository_owner }}/${{ env.IMAGE_NAME }} ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} |
64 | 37 |
|
65 | | - # Sign the resulting Docker image digest except on PRs. |
66 | | - # This will only write to the public Rekor transparency log when the Docker |
67 | | - # repository is public to avoid leaking data. If you would like to publish |
68 | | - # transparency data even for private images, pass --force to cosign below. |
69 | | - # https://github.com/sigstore/cosign |
70 | | - - name: Sign the published Docker image |
71 | | - if: ${{ github.event_name != 'pull_request' }} |
72 | | - env: |
73 | | - # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable |
74 | | - TAGS: ${{ steps.meta.outputs.tags }} |
75 | | - DIGEST: ${{ steps.build-and-push.outputs.digest }} |
76 | | - # This step uses the identity token to provision an ephemeral certificate |
77 | | - # against the sigstore community Fulcio instance. |
78 | | - run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} |
| 38 | + - name: Tag (SHA) |
| 39 | + run: docker tag ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.sha_short }} |
| 40 | + |
| 41 | + - name: Push (Latest) |
| 42 | + run: docker push ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest |
| 43 | + |
| 44 | + - name: Push (SHA) |
| 45 | + run: docker push ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.sha_short }} |
| 46 | + |
| 47 | + - uses: docker/build-push-action@v1 |
| 48 | + with: |
| 49 | + # The two entries below need to be entered as |
| 50 | + # github secrets. The "secret" names are "DOCKER_USERNAME" |
| 51 | + # and "DOCKER_PASSWORD". See https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository |
| 52 | + # for detailed instructions. |
| 53 | + # |
| 54 | + # DO NOT EDIT THESE ENTRIES HERE. Doing so will |
| 55 | + # expose your docker username and password on github. |
| 56 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 57 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 58 | + # Use the environment variable on first few lines to set repo name--just centralizes changes |
| 59 | + repository: ${{ env.repo-name }} |
| 60 | + tag_with_ref: true |
| 61 | + tag_with_sha: true |
| 62 | + tags: latest |
0 commit comments