Skip to content

Feat/actions ci (#11) #11

Feat/actions ci (#11)

Feat/actions ci (#11) #11

Workflow file for this run

name: Docker Publish
on:
push:
branches:
- main
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# 1. Checkout the repository
- name: Checkout repository
uses: actions/checkout@v3
# 2. Log in to Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# 3. Build and tag the Docker image
- name: Build Docker image
run: |
docker build -t endermaru/22-5-team1-server:latest .
docker tag endermaru/22-5-team1-server:latest endermaru/22-5-team1-server:${{ github.sha }}
# 4. Push the Docker image to Docker Hub
- name: Push Docker image
run: |
docker push endermaru/22-5-team1-server:latest
docker push endermaru/22-5-team1-server:${{ github.sha }}
deploy:
runs-on: ubuntu-latest
needs: build-and-push
steps:
# 1. Deploy to EC2 via SSH
- name: Deploy to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script: |
docker-compose down
docker-compose pull
docker-compose up -d