Autodeployment
This commit is contained in:
parent
525faf34e6
commit
8bd64f03c8
@ -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:
|
||||||
@ -48,4 +48,28 @@ jobs:
|
|||||||
context: .
|
context: .
|
||||||
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"
|
||||||
|
Loading…
Reference in New Issue
Block a user