All checks were successful
Increase Version / bump-version (push) Successful in 15s
108 lines
3.4 KiB
YAML
108 lines
3.4 KiB
YAML
name: Docker Image CI
|
|
|
|
on:
|
|
workflow_dispatch: # Start alleen als het handmatig of via API wordt getriggerd
|
|
|
|
jobs:
|
|
bump-version:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Configure Git
|
|
run: |
|
|
git config --global user.name "Gitea Actions"
|
|
git config --global user.email "actions@gitea.local"
|
|
|
|
- name: Bump version in package.json
|
|
run: |
|
|
npm version patch --no-git-tag-version
|
|
git add package.json package-lock.json
|
|
git commit -m "chore: bump version [skip ci]" || echo "No changes to commit"
|
|
git push origin main
|
|
|
|
build-and-push:
|
|
needs: bump-version
|
|
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
|
|
|
|
# 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 --tag veenm/paypoint:$VERSION --tag veenm/paypoint:latest --platform linux/amd64
|
|
|
|
# Stap 5: Docker-image pushen naar Docker Hub (huidige versie tag)
|
|
- name: Push the Docker image (version)
|
|
run: |
|
|
VERSION=$(cat version.txt)
|
|
docker push veenm/paypoint:$VERSION
|
|
|
|
# Stap 6: Docker-image pushen naar Docker Hub (latest tag)
|
|
- name: Push the Docker image (latest)
|
|
run: docker push veenm/paypoint:latest
|
|
|
|
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 TrueNAS SCALE server en update de container
|
|
- name: SSH into TrueNAS SCALE and update Docker container
|
|
uses: appleboy/ssh-action@v0.1.10
|
|
with:
|
|
host: ${{ secrets.TRUENAS_HOST }}
|
|
username: ${{ secrets.TRUENAS_USER }}
|
|
password: ${{ secrets.TRUENAS_PASSWORD }}
|
|
port: ${{ secrets.TRUENAS_PORT }}
|
|
script: |
|
|
VERSION=${{ env.VERSION }}
|
|
echo "Gekozen versie: $VERSION"
|
|
|
|
# Stop en verwijder de huidige container
|
|
docker stop paypoint || true
|
|
docker rm paypoint || true
|
|
|
|
# Haal de nieuwste image binnen
|
|
docker pull veenm/paypoint:$VERSION
|
|
|
|
# Start een nieuwe container
|
|
docker run -d --name paypoint --restart unless-stopped -p 15001:80 veenm/paypoint:$VERSION
|
|
|
|
# Opruimen oude images
|
|
docker image prune -f
|