-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (74 loc) · 2.65 KB
/
docker-image.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: CI
on:
push:
branches:
- '*'
env:
ACCOUNT_NAME: rtav3d
IMAGE_NAME: soloanvill-backend
IMAGE_VERSION: 0.1.2
HOST_PORT: 80
CONTAINER_PORT: 8080
PROJECT_NAME: soloanvill_backend
jobs:
build_and_test:
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build image
run: docker buildx build --platform linux/amd64 -t $ACCOUNT_NAME/$IMAGE_NAME:$IMAGE_VERSION .
- name: Run docker compose
run: |
sed -i -e "s/ACCOUNT_NAME/$ACCOUNT_NAME/" -e "s/IMAGE_NAME/$IMAGE_NAME/g" -e "s/IMAGE_VERSION/$IMAGE_VERSION/" ./docker-compose.yml
sudo apt-get install -y postgresql-client netcat-traditional
docker compose up -d
- name: Check application status
run: |
docker ps
docker logs soloanvill_backend-soloanvill-backend-1
docker logs soloanvill_backend-db-1
status=$(curl -s 127.0.0.1/api/health | grep -oP '(?<="status":")[^"]+')
curl -s 127.0.0.1/api/health
if [[ "$status" == "up" ]]; then
echo -e "Successful\nApplication status - $status"
else
echo "Application run failed\nApplication status - $status"
exit 1
fi
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.CI_DOCKERHUB_LOGIN }}
password: ${{ secrets.CI_DOCKERHUB_PASS }}
- name: Push Docker image
run: docker push $ACCOUNT_NAME/$IMAGE_NAME:$IMAGE_VERSION
- name: Send telegram message on push
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
${{ github.actor }} created commit:
Commit message: ${{ github.event.commits[0].message }}
Repository: ${{ github.repository }}
See changes: https://github.com/${{ github.repository }}/commit/${{github.sha}}
update_k3s_repo:
runs-on: ubuntu-24.04
needs: build_and_test
steps:
- name: Checkout repository K3s
uses: actions/checkout@v4
with:
repository: ${{ secrets.K3S_REPO }}
token: ${{ secrets.K3S_TOKEN }}
- name: Update image version in manifest
run: |
sed -i "s/image:.*/image: $ACCOUNT_NAME\/$IMAGE_NAME:$IMAGE_VERSION/g" $PROJECT_NAME/deployment.yml
- name: Commit and push changes
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
git add .
git commit -m "${{ github.event.commits[0].message }}"
git push