Files
weetikveel/.github/workflows/docker-image.yml
2024-12-03 09:54:47 +01:00

92 lines
2.7 KiB
YAML

name: Docker Image CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
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
# 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 build . --file Dockerfile --tag veenm/weetikveel:$VERSION --tag veenm/weetikveel:latest
# 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/weetikveel:$VERSION
# Stap 6: Docker-image pushen naar Docker Hub (latest tag)
- name: Push the Docker image (latest)
run: docker push veenm/weetikveel: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: Gebruik het versienummer in de deployment
- name: Use VERSION from artifact
run: |
VERSION=$(cat version.txt)
echo "De versie is: $VERSION"
# Stap 3: Maak verbinding via SSH naar de TrueNAS SCALE server
- name: SSH into TrueNAS SCALE
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: |
# Kubernetes-configuratie instellen
export KUBEVERSION=/etc/rancher/k3s/k3s.yaml
export KUBECONFIG=$KUBEVERSION
# Update deployment
k3s kubectl apply -f deployment.yaml
k3s kubectl apply -f service.yaml
# Update image in deployment
VERSION=$(cat version.txt)
k3s kubectl set image deployment/weetikveel weetikveel=veenm/weetikveel:$VERSION --record
# Controle en status
k3s kubectl rollout status deployment/weetikveel
k3s kubectl get pods
k3s kubectl get service