Skip to content

Update docker-image.yml #31

Update docker-image.yml

Update docker-image.yml #31

Workflow file for this run

name: Docker Image CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
jobs:
# test:
# name: Jest Tests
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
# - name: Set up NodeJS
# uses: actions/setup-node@v1
# with:
# node-version: 20
# - name: Install all dependencies
# run: npm install
# - name: Run Tests
# run: npm test
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Docker auth
uses: docker/login-action@v1
with:
username: ${{ env.DOCKER_USER }}
password: ${{ env.DOCKER_PASSWORD }}
- name: Build and push Docker Image
uses: docker/build-push-action@v2
with:
context: ./
push: true
dockerfile: ./Dockerfile
tags: jaderodev/aup-backend:latest
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Docker auth
uses: docker/login-action@v1
with:
username: ${{ env.DOCKER_USER }}
password: ${{ env.DOCKER_PASSWORD }}
- name: Set permissions for private key
run: |
echo "${{ secrets.AWS_PRIVATE_KEY }}" > key.pem
chmod 600 key.pem
- name: Move to project folder
run: |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.228.164.55 'cd backend/ && sudo docker compose down'
- name: Remove old image
run: |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.228.164.55 'sudo docker image rm -f backend-aup-backend:latest'
- name: Run new containers
run: |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.228.164.55 'cd backend/ && git pull && sudo docker compose up -d'