From bbeb093b7d850927eaa3664225585199782575d3 Mon Sep 17 00:00:00 2001 From: Jonathan Inge Arvesen Folland Date: Mon, 3 Mar 2025 19:07:56 +0100 Subject: [PATCH] Update docker.yml --- .github/workflows/docker.yml | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 6d72274..95a1dfe 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,11 +3,12 @@ name: Deploy Docker on Code Update on: push: branches: - - main + - main jobs: build_and_deploy: runs-on: self-hosted + steps: - name: Checkout code uses: actions/checkout@v2 @@ -15,22 +16,38 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: SSH into server and build/deploy Docker + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build Docker images + run: | + docker build -t jonafoll/frontend:latest ./frontend + docker build -t jonafoll/backend:latest ./backend + + - name: Push Docker images to Docker Hub run: | - # SSH into your server, build the images, and deploy them + docker push jonafoll/frontend:latest + docker push jonafoll/backend:latest + + - name: SSH into server and deploy Docker + run: | + # SSH into your server, pull the images, and deploy them ssh jifollan@tdt4242-04.idi.ntnu.no << 'EOF' cd secfit - git pull + git pull # Stop and remove old containers docker-compose down - # Build the Docker images (only rebuild if necessary) - docker-compose build + # Pull the latest images from Docker Hub + docker pull jonafoll/frontend:latest + docker pull jonafoll/backend:latest # Run the containers in detached mode docker-compose up -d EOF env: - SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} # You need to add your private key to GitHub Secrets - + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}