.github/workflows/cd.yml #28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: workflow_dispatch | |
jobs: | |
deploy : | |
runs-on: ubuntu-latest | |
steps: | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-1 | |
- name: Login to Amazon ECR Public | |
run: | | |
aws ecr-public get-login-password --region us-east-1 | sudo docker login --username AWS --password-stdin public.ecr.aws | |
- name: Docker pull from ECR Public | |
env: | |
REGISTRY_ALIAS: ${{ secrets.DEV_ECR_REGISTRY_ALIAS }} | |
REPOSITORY: distribute/dev | |
run: sudo docker pull public.ecr.aws/${{ secrets.DEV_ECR_REGISTRY_ALIAS }}/distribute/dev:latest | |
- name: SSH into EC2 and Deploy Docker | |
env: | |
SSH_KEY: ${{ secrets.DEV_EC2_SSH_KEY }} | |
HOST: 3.39.206.214 | |
USER: ubuntu | |
run: | | |
echo "${SSH_KEY}" > ec2_key.pem | |
chmod 600 ec2_key.pem | |
# Connect to EC2 and run deployment commands | |
ssh -o StrictHostKeyChecking=no -i ec2_key.pem ${USER}@${HOST} << 'EOF' | |
# Stop and remove existing container if running | |
sudo docker stop distribute-container || true | |
sudo docker rm distribute-container || true | |
sudo docker pull public.ecr.aws/${{ secrets.DEV_ECR_REGISTRY_ALIAS }}/distribute/dev:latest | |
sudo docker run -it -d -p 80:8080 --name distribute-container public.ecr.aws/${{ secrets.DEV_ECR_REGISTRY_ALIAS }}/distribute/dev:latest |