-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (50 loc) · 1.72 KB
/
build.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
name: Build
on: push
jobs:
build:
runs-on: ubuntu-latest
name: Build
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Build image
run: |
docker build . \
--no-cache \
--file docker/Dockerfile \
--tag search-api
- name: Scan image
uses: aquasecurity/trivy-action@0.10.0
with:
image-ref: 'search-api'
severity: 'CRITICAL,HIGH'
format: 'sarif'
output: 'trivy.sarif'
- name: Upload scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'trivy.sarif'
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image for development
run: |
IMAGE_ID=$(echo "ghcr.io/${{ github.repository }}" | tr '[A-Z]' '[a-z]')
GIT_SHORT_HASH=$(git rev-parse --short "$GITHUB_SHA")
DATE=$(date "+%Y%m%d%H%M%S")
VERSION="dev.$DATE.$GIT_SHORT_HASH.${{ github.run_number }}"
echo "VERSION=$VERSION"
docker tag search-api $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: Push image for production
if: startsWith(github.event.ref, 'refs/tags/v')
run: |
IMAGE_ID=$(echo "ghcr.io/${{ github.repository }}" | tr '[A-Z]' '[a-z]')
docker tag search-api $IMAGE_ID:$GITHUB_REF_NAME
docker push $IMAGE_ID:$GITHUB_REF_NAME
docker tag search-api $IMAGE_ID:latest
docker push $IMAGE_ID:latest