Files
paypoint-frontend/.github/workflows/deploy-docker-to-tst.yml
veenm ddabbc62d1
All checks were successful
Docker Image CI / build-and-push (push) Successful in 41s
Docker Image CI / deploy (push) Successful in 28s
commit messages toegevoegd aan pipeline fix 2
2025-03-16 22:45:25 +01:00

119 lines
3.9 KiB
YAML

name: Docker Image CI
on:
push:
branches:
- develop
tags:
- "docker-build-*"
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# Stap 1: Code ophalen
- uses: actions/checkout@v4
# Stap 2: Versienummer ophalen uit package.json en opslaan als artifact
- name: Extract Angular version
run: |
echo "$(cat package.json | jq -r '.version')" > version.txt
- name: Save version as artifact
uses: actions/upload-artifact@v3
with:
name: version
path: version.txt
- name: Notify Mattermost via Bot
env:
REPO: ${{ gitea.repository }}
BRANCH: ${{ gitea.ref }}
MATTERMOST_BOT_TOKEN: ${{ secrets.MATTERMOST_BOT_TOKEN }}
run: |
curl --fail -X POST -H "Authorization: Bearer $MATTERMOST_BOT_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"channel_id": "9a8obynkd7rctk6qf8rfe6oppy",
"message": "@all 🚀 *Build gestart!* Een nieuwe build is begonnen voor de repository *'"$REPO"'* op branch *'"$BRANCH"'*."
}' \
https://mattermost.melvanveen.nl/api/v4/posts
# Stap 3: Inloggen bij Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Stap 4: Docker-image bouwen en taggen met Angular-versie
- name: Build the Docker image
run: |
VERSION=$(cat version.txt)
docker buildx build . --file Dockerfile-tst --tag veenm/paypoint:$VERSION-SNAPSHOT --platform linux/amd64
# Stap 5: Docker-image pushen naar Docker Hub (huidige versie tag)
- name: Push the Docker image (version-snapshot)
run: |
VERSION=$(cat version.txt)
docker push veenm/paypoint:$VERSION-SNAPSHOT
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
# Stap 1: Artifact ophalen
- name: Download version artifact
uses: actions/download-artifact@v3
with:
name: version
# Stap 2: Lees versie uit het artifact
- name: Read version
id: read_version
run: echo "VERSION=$(cat version.txt)" >> $GITHUB_ENV
# Stap 3: Maak verbinding via SSH naar de Alpine server en update de container
- name: SSH into Alpine and update Docker container
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.ALPINE_HOST }}
username: ${{ secrets.ALPINE_USER }}
password: ${{ secrets.ALPINE_PASSWORD }}
script: |
VERSION=${{ env.VERSION }}
echo "Gekozen versie: $VERSION-SNAPSHOT"
# Stop en verwijder de huidige container
docker stop paypoint-frontend || true
docker rm paypoint-frontend || true
# Haal de nieuwste image binnen
docker pull veenm/paypoint:$VERSION-SNAPSHOT
# Start een nieuwe container
docker run -d --name paypoint-frontend --restart unless-stopped -p 15000:80 veenm/paypoint:$VERSION-SNAPSHOT
# Opruimen oude images
docker image prune -f
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Notify Mattermost via Bot
env:
VERSION: ${{ env.VERSION }}
run: |
COMMITS=$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"- %s")
curl --fail -X POST -H "Authorization: Bearer tspcwdn5rbdk8kkmnex6h1nfha" \
-H 'Content-Type: application/json' \
-d '{
"channel_id": "9a8obynkd7rctk6qf8rfe6oppy",
"message": "@all ✅ *Build is geslaagd!* Versie '"$VERSION"'-SNAPSHOT staat klaar op https://test-paypoint.melvanveen.nl\n\n*Changelog:*\n'"${COMMITS}"'"
}' \
https://mattermost.melvanveen.nl/api/v4/posts