Center Cicd

This commit is contained in:
2026-10-02 13:40:39 +03:30
parent 7fc8140dfb
commit 02e38e435b
3 changed files with 111 additions and 0 deletions
+88
View File
@@ -0,0 +1,88 @@
name: Deploy to Staging
on:
push:
branches: [ dev ]
concurrency:
group: staging-${{ github.repository }}
cancel-in-progress: false
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Generate Version
id: version
run: echo "VERSION=1.0.0-dev.${{ github.run_number }}" >> $GITHUB_OUTPUT
- name: Build Docker Image
env:
IMAGE_NAME: ${{ vars.SERVICE_NAME || github.event.repository.name }}
VERSION: ${{ steps.version.outputs.VERSION }}
run: |
docker build \
--tag ${{ secrets.NEXUS_REGISTRY }}/$IMAGE_NAME:$VERSION \
--tag ${{ secrets.NEXUS_REGISTRY }}/$IMAGE_NAME:1.0.0-latest \
--build-arg NEXUS_REGISTRY=${{ secrets.NEXUS_REGISTRY }} \
.
- name: Login to Nexus
uses: docker/login-action@v3
with:
registry: ${{ secrets.NEXUS_REGISTRY }}
username: ${{ secrets.NEXUS_USER }}
password: ${{ secrets.NEXUS_PASS }}
- name: Push to Nexus
env:
IMAGE_NAME: ${{ vars.SERVICE_NAME || github.event.repository.name }}
VERSION: ${{ steps.version.outputs.VERSION }}
run: |
docker push ${{ secrets.NEXUS_REGISTRY }}/$IMAGE_NAME:$VERSION
docker push ${{ secrets.NEXUS_REGISTRY }}/$IMAGE_NAME:1.0.0-latest
- name: Deploy to Staging
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
STAGING_HOST: ${{ secrets.STAGING_HOST }}
STAGING_USER: ${{ secrets.STAGING_USER }}
IMAGE_NAME: ${{ vars.SERVICE_NAME || github.event.repository.name }}
VERSION: ${{ steps.version.outputs.VERSION }}
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H $STAGING_HOST >> ~/.ssh/known_hosts
ssh $STAGING_USER@$STAGING_HOST "
cd /srv/staging/narng-platform/compose
docker compose pull $IMAGE_NAME
export ${IMAGE_NAME}_TAG=$VERSION
docker compose up -d $IMAGE_NAME
"
- name: Wait for Health Check
env:
IMAGE_NAME: ${{ vars.SERVICE_NAME || github.event.repository.name }}
run: sleep 15
- name: Run Smoke Test
env:
STAGING_HOST: ${{ secrets.STAGING_HOST }}
run: |
STATUS=$(curl -sk -o /dev/null -w "%{http_code}" https://api.$STAGING_HOST/api/categories || echo "000")
if [ "$STATUS" != "200" ]; then
echo "Smoke test failed with status $STATUS"
exit 1
fi
echo "Smoke test passed!"