104 lines
3.7 KiB
YAML
104 lines
3.7 KiB
YAML
name: Build, Push & Deploy Angular App
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- '*'
|
|
|
|
env:
|
|
IMAGE_NAME: ${{ vars.IMAGE_NAME }}
|
|
GITEA_REGISTRY: ${{ vars.IMAGE_REGISTRY }}
|
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
|
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
|
|
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
|
CI_REGISTRY_USER: ${{ secrets.CI_REGISTRY_USER }}
|
|
CI_REGISTRY_PASSWORD: ${{ secrets.CI_REGISTRY_PASSWORD }}
|
|
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
TAG: ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || 'latest' }}
|
|
|
|
jobs:
|
|
# build:
|
|
# name: 🏗️ Build Docker Image
|
|
# runs-on: ubuntu-latest
|
|
# steps:
|
|
# - uses: actions/checkout@v3
|
|
#
|
|
# - name: Install Docker client
|
|
# run: |
|
|
# sudo apt-get update
|
|
# sudo apt-get install -y docker.io bash
|
|
#
|
|
# - name: Build Docker Image
|
|
# run: |
|
|
# chmod +x ./docker/build.sh
|
|
# cd docker
|
|
# ./build.sh "${IMAGE_NAME}" "${TAG}"
|
|
|
|
push:
|
|
name: ⬆️ Build and Push Image to Gitea Registry
|
|
runs-on: ubuntu-latest
|
|
# needs: build
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Build and Push Image
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y docker.io bash
|
|
cd docker
|
|
chmod +x ./push-to-gitea.sh
|
|
export GITEA_REGISTRY="${GITEA_REGISTRY}"
|
|
export GITEA_USER="${CI_REGISTRY_USER}"
|
|
export GITEA_TOKEN="${CI_REGISTRY_PASSWORD}"
|
|
echo "${GITEA_REGISTRY}"
|
|
echo "${CI_REGISTRY_USER}"
|
|
echo "${CI_REGISTRY_PASSWORD}"
|
|
./push-to-gitea.sh "${IMAGE_NAME}" "${TAG}"
|
|
|
|
deploy:
|
|
name: 🚀 Deploy to Remote Server
|
|
runs-on: ubuntu-latest
|
|
needs: push
|
|
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
|
|
steps:
|
|
- name: Prepare environment
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y openssh-client docker.io
|
|
|
|
- name: Deploy via SSH
|
|
run: |
|
|
echo "${DEPLOY_KEY}" > /tmp/deploy_key.pem
|
|
chmod 600 /tmp/deploy_key.pem
|
|
|
|
ssh -i /tmp/deploy_key.pem -o StrictHostKeyChecking=no \
|
|
${DEPLOY_USER}@${DEPLOY_HOST} <<EOF
|
|
docker login ${GITEA_REGISTRY} -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}"
|
|
docker pull ${GITEA_REGISTRY}/${CI_REGISTRY_USER}/${IMAGE_NAME}:${TAG}
|
|
docker stop ${IMAGE_NAME} || true
|
|
docker rm ${IMAGE_NAME} || true
|
|
docker run -d --name ${IMAGE_NAME} -p 80:80 ${GITEA_REGISTRY}/${CI_REGISTRY_USER}/${IMAGE_NAME}:${TAG}
|
|
EOF
|
|
|
|
# notify:
|
|
# name: 🔔 Notify Deployment Result
|
|
# runs-on: ubuntu-latest
|
|
# needs: deploy
|
|
# if: always()
|
|
# steps:
|
|
# - name: Send Discord Notification
|
|
# run: |
|
|
# STATUS=${{ job.status }}
|
|
# MESSAGE="🚀 *Angular-Web-App Deployment* (${{ github.ref_name }}) finished with status: **${STATUS}**"
|
|
# curl -H "Content-Type: application/json" \
|
|
# -X POST \
|
|
# -d "{\"content\": \"${MESSAGE}\"}" \
|
|
# ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
|
|
# deploy-prod:
|
|
# if: startsWith(github.ref, 'refs/tags/')
|
|
# deploy-staging:
|
|
# if: github.ref == 'refs/heads/dev'
|