forked from shardus/relayer-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (70 loc) · 2.36 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Create and publish a Docker image
on:
push:
branches: ['dev']
workflow_dispatch:
inputs:
tag:
description: 'Tag for the Docker image'
required: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
display-image-name:
runs-on: ubuntu-latest
steps:
- name: Display IMAGE_NAME
run: echo "IMAGE_NAME is ${{ env.IMAGE_NAME }}"
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get short commit hash and determine branch name
id: set-env-vars
run: |
# Get short commit hash
echo "SHORT_COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
# Determine branch name
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV # Source branch of the PR
else
echo "BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV # Actual branch name for push events
fi
- name: Set Docker image tag
id: set-docker-tag
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "DOCKER_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
else
echo "DOCKER_TAG=${{ env.BRANCH_NAME }}-${{ env.SHORT_COMMIT_HASH }}" >> $GITHUB_ENV
fi
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}::${{ env.DOCKER_TAG }}
labels: |
version=${{ env.SHORT_COMMIT_HASH }}
branch=${{ env.BRANCH_NAME }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true