From 7988830538d70180906cd701b160d98435b7f5f5 Mon Sep 17 00:00:00 2001 From: kaxada Date: Tue, 26 Dec 2023 16:31:07 +0300 Subject: [PATCH] added step to remove old images and containers at once --- .github/workflows/deploy.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9111c50..a805f64 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,6 +13,19 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Remove old Docker images + uses: appleboy/ssh-action@v0.1.10 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + script: | + if docker inspect ${{ env.IMAGE_NAME }} >/dev/null 2>&1; then + docker stop ${{ env.IMAGE_NAME }} + docker rm ${{ env.IMAGE_NAME }} + docker images --filter "reference=${{ env.IMAGE_NAME }}*" -q | xargs docker rmi -f || true + fi + - name: Build Docker image run: docker build -t ${{ env.IMAGE_NAME }}:${{ github.sha }} . @@ -35,10 +48,6 @@ jobs: username: ${{ secrets.USERNAME }} password: ${{ secrets.PASSWORD }} script: | - if docker inspect ${{ env.IMAGE_NAME }} >/dev/null 2>&1; then - docker stop ${{ env.IMAGE_NAME }} - docker rm ${{ env.IMAGE_NAME }} - fi docker load -i ~/badging.tar docker run -d \ -p ${{ secrets.PORT }}:${{ secrets.PORT }} \