Skip to content

ci: update port

ci: update port #1

Workflow file for this run

name: Build and Deploy to EC2
on:
push:
branches: ["main"]
paths:
- "backend/**"
- "frontend/**"
- "docker-compose.yml"
pull_request:
branches: ["main"]
paths:
- "backend/**"
- "frontend/**"
- "docker-compose.yml"
workflow_dispatch:
jobs:
build-backend:
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push' && contains((github.event.head_commit.added || github.event.head_commit.modified || github.event.head_commit.removed), 'backend/') ||
github.event_name == 'pull_request' && contains(github.event.pull_request.changed_files, 'backend/')
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/z4n6o0v4
- name: Build and Push Backend Docker Image
run: |
ECR_REPO_SERVER=public.ecr.aws/z4n6o0v4/myas/server
docker build -t $ECR_REPO_SERVER:latest -f backend/Dockerfile backend
docker push $ECR_REPO_SERVER:latest
build-frontend:
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push' && contains((github.event.head_commit.added || github.event.head_commit.modified || github.event.head_commit.removed), 'frontend/') ||
github.event_name == 'pull_request' && contains(github.event.pull_request.changed_files, 'frontend/')
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/z4n6o0v4
- name: Build and Push Frontend Docker Image
run: |
ECR_REPO_CLIENT=public.ecr.aws/z4n6o0v4/myas/client
docker build -t $ECR_REPO_CLIENT:latest -f frontend/Dockerfile frontend
docker push $ECR_REPO_CLIENT:latest
deploy-backend:
needs: build-backend
runs-on: ubuntu-latest
if: success() && needs.build-backend.result == 'success'
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Set up SSH
uses: webfactory/ssh-agent@v0.5.3
with:
ssh-private-key: ${{ secrets.EC2_PRIVATE_KEY }}
- name: Upload Docker Compose files to EC2
run: |
HOST=${{ secrets.EC2_HOST }}
USER=${{ secrets.EC2_USER }}
PORT=22
scp -o StrictHostKeyChecking=no -P $PORT docker-compose.yml $USER@$HOST:/home/$USER/myas/docker-compose.yml
- name: Deploy Backend to EC2
run: |
HOST=${{ secrets.EC2_HOST }}
USER=${{ secrets.EC2_USER }}
PORT=22
ssh -o StrictHostKeyChecking=no $USER@$HOST << 'EOF'
docker login --username AWS --password-stdin public.ecr.aws/z4n6o0v4
docker pull public.ecr.aws/z4n6o0v4/myas/server:latest
sudo docker compose -f /home/$USER/myas/docker-compose.yml up -d myas_server
EOF
deploy-frontend:
needs: build-frontend
runs-on: ubuntu-latest
if: success() && needs.build-frontend.result == 'success'
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Set up SSH
uses: webfactory/ssh-agent@v0.5.3
with:
ssh-private-key: ${{ secrets.EC2_PRIVATE_KEY }}
- name: Upload Docker Compose files to EC2
run: |
HOST=${{ secrets.EC2_HOST }}
USER=${{ secrets.EC2_USER }}
PORT=22
scp -o StrictHostKeyChecking=no -P $PORT docker-compose.yml $USER@$HOST:/home/$USER/myas/docker-compose.yml
- name: Deploy Frontend to EC2
run: |
HOST=${{ secrets.EC2_HOST }}
USER=${{ secrets.EC2_USER }}
PORT=22
ssh -o StrictHostKeyChecking=no $USER@$HOST << 'EOF'
docker login --username AWS --password-stdin public.ecr.aws/z4n6o0v4
docker pull public.ecr.aws/z4n6o0v4/myas/client:latest
sudo docker compose -f /home/$USER/myas/docker-compose.yml up -d myas_client
EOF