try fix CI #18. Database.host value get from ENV #42
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |