CI Test
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m10s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m10s
This commit is contained in:
67
.gitea/workflows/build-and-push.yaml
Normal file
67
.gitea/workflows/build-and-push.yaml
Normal file
@@ -0,0 +1,67 @@
|
||||
name: Build and Push Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Determine Image Tag
|
||||
id: tag
|
||||
run: |
|
||||
# Prüfe ob es ein Git Tag ist
|
||||
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
|
||||
# Verwende den Tag-Namen (z.B. v1.0.0)
|
||||
TAG="${{ github.ref_name }}"
|
||||
elif [[ "${{ github.ref_name }}" == "main" ]]; then
|
||||
# Für main Branch: verwende 'latest'
|
||||
TAG="latest"
|
||||
else
|
||||
# Für andere Branches: verwende Branch-Name + kurzen Commit-SHA
|
||||
TAG="${{ github.ref_name }}-${{ github.sha }}"
|
||||
TAG="${TAG:0:50}" # Limit auf 50 Zeichen
|
||||
fi
|
||||
echo "IMAGE_TAG=${TAG}" >> $GITHUB_OUTPUT
|
||||
echo "📦 Image Tag: ${TAG}"
|
||||
|
||||
- name: Create .env file from secrets and variables
|
||||
run: |
|
||||
cd docker
|
||||
cat > .env << EOF
|
||||
REGISTRY_URL=${{ vars.REGISTRY_URL }}
|
||||
NAMESPACE=${{ vars.NAMESPACE }}
|
||||
REPO_NAME=${{ vars.REPO_NAME }}
|
||||
IMAGE_TAG=${{ steps.tag.outputs.IMAGE_TAG }}
|
||||
CI_GITEA_USER=${{ secrets.CI_GITEA_USER }}
|
||||
CI_GITEA_TOKEN=${{ secrets.CI_GITEA_TOKEN }}
|
||||
EOF
|
||||
echo "✅ .env file created with IMAGE_TAG=${{ steps.tag.outputs.IMAGE_TAG }}"
|
||||
|
||||
- name: Build Docker Image
|
||||
run: |
|
||||
cd docker
|
||||
chmod +x build.sh
|
||||
./build.sh
|
||||
|
||||
- name: Push Docker Image to Registry
|
||||
run: |
|
||||
cd docker
|
||||
chmod +x push.sh
|
||||
./push.sh
|
||||
|
||||
- name: Summary
|
||||
run: |
|
||||
echo "🎉 Build and Push completed successfully!"
|
||||
echo "📦 Image: ${{ vars.REGISTRY_URL }}/${{ vars.NAMESPACE }}/${{ vars.REPO_NAME }}:${{ steps.tag.outputs.IMAGE_TAG }}"
|
||||
@@ -1,103 +0,0 @@
|
||||
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
|
||||
env:
|
||||
GITEA_REGISTRY: ${{ vars.IMAGE_REGISTRY }}
|
||||
GITEA_USER: ${{ secrets.CI_REGISTRY_USER }}
|
||||
GITEA_TOKEN: ${{ secrets.CI_REGISTRY_PASSWORD }}
|
||||
IMAGE_NAME: ${{ vars.IMAGE_NAME }}
|
||||
TAG: ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || 'latest' }}
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y docker.io bash
|
||||
cd docker
|
||||
chmod +x ./push-to-gitea.sh
|
||||
./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'
|
||||
Reference in New Issue
Block a user