Autodeployment
Some checks failed
Build Docker Image and Deploy / Build Image and push to Registry (push) Failing after 18s
Build Docker Image and Deploy / Deploy on webserver (push) Has been skipped

This commit is contained in:
Cyril Šebek 2024-07-07 21:11:32 +02:00
parent 525faf34e6
commit 8bd64f03c8
Signed by: blboun3
SSH Key Fingerprint: SHA256:n9dMtOPzgsD+CCerUJslEnU2dzVanbaIv0XDQVRVjeg

View File

@ -8,11 +8,11 @@ on:
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. # Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env: env:
REGISTRY: 10.69.13.154:5000
IMAGE_NAME: ${{ github.repository }} IMAGE_NAME: ${{ github.repository }}
jobs: jobs:
build-and-push-image: build-and-push-image:
name: Build Image and push to Registry
runs-on: ubuntu-latest runs-on: ubuntu-latest
# Sets the permissions granted to the GITHUB_TOKEN for the actions in this job. # Sets the permissions granted to the GITHUB_TOKEN for the actions in this job.
permissions: permissions:
@ -49,3 +49,27 @@ jobs:
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
deploy:
name: Deploy on webserver
runs-on: ubuntu-latest
needs: build-and-push-image
steps:
- name: Install SSH key for target server
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.SSH_PRIV_KEY }}
- name: Login to registry
run: ssh ${{ env.TARGET_USER }}@${{ env.TARGET }} "docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} ${{ env.REGISTRY }}"
- name: Pull new image
run: ssh ${{ env.TARGET_USER }}@{{ env.TARGET }} "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
- name: Logout from registry
run: ssh ${{ env.TARGET_USER }}@{{ env.TARGET }} "docker logout ${{ env.REGISTRY }}"
- name: Stop and Remove the container
run: ssh ${{ env.TARGET_USER }}@{{ env.TARGET }} "docker stop ${{ env.IMAGE_NAME }} && docker remove ${{ env.IMAGE_NAME }}"
- name: Recreate the container
run: ssh ${{ env.TARGET_USER }}@{{ env.TARGET }} "docker run --name=${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}:latest"
- name: Clean old images
run: ssh ${{ env.TARGET_USER }}@{{ env.TARGET }} "docker image prune -a"