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 run: | curl -X POST -H "Authorization: Bearer tspcwdn5rbdk8kkmnex6h1nfha" \ -H 'Content-Type: application/json' \ -d '{ "channel_id": "9a8obynkd7rctk6qf8rfe6oppy", "message": "@all \nšŸš€ *Build gestart!* Een nieuwe build [${{VERSION}}-SNAPSHOT] is begonnen voor de repository *${{ gitea.repository }}* op branch *${{ gitea.ref }}*." }' \ 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: Notify Mattermost via Bot run: | curl -X POST -H "Authorization: Bearer tspcwdn5rbdk8kkmnex6h1nfha" \ -H 'Content-Type: application/json' \ -d '{ "channel_id": "9a8obynkd7rctk6qf8rfe6oppy", "message": "@all \nāœ… *Build is geslaagd!* Versie ${{VERSION}}-SNAPSHOT staat klaar op https://test-paypoint.melvanveen.nl" }' \ https://mattermost.melvanveen.nl/api/v4/posts