-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (55 loc) · 1.84 KB
/
build.yml
File metadata and controls
63 lines (55 loc) · 1.84 KB
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 and Push to Docker Hub"
on:
push:
branches:
- main
paths-ignore:
- 'docker-compose.yaml'
jobs:
build:
name: "Build and Push to Docker Hub"
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Build, tag
id: build-image
env:
REGISTRY: r3dshadow
REPOSITORY: compose-gitops
run: |
IMAGE_TAG=cg-$(git rev-parse --short HEAD)
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
echo "image_tag=$IMAGE_TAG" >> "$GITHUB_OUTPUT"
echo "image=$REGISTRY/$REPOSITORY:$IMAGE_TAG" >> "$GITHUB_OUTPUT"
- name: Scan image
uses: anchore/scan-action@v3
with:
image: ${{ steps.build-image.outputs.image }}
fail-build: true
severity-cutoff: critical
output-format: table
continue-on-error: true
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: push image to Docker hub
env:
IMAGE_NAME: ${{ steps.build-image.outputs.image }}
id: push-image
run: |
docker push $IMAGE_NAME
- name: Deployment Update
env:
IMAGE_NAME: ${{ steps.build-image.outputs.image }}
IMAGE_TAG: ${{ steps.build-image.outputs.image_tag }}
run: |
CURRENT_TAG=$(cat docker-compose.yaml | grep -i image| awk -F ':' '{print $NF}')
sed -i "s/$CURRENT_TAG/$IMAGE_TAG/" docker-compose.yaml
git config --global user.email "user@github.com"
git config --global user.name "Git Actions"
git add .
git commit -m "[Deployment commit] $IMAGE_TAG"
git push