Function key set (#617) #155
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
name: Docker Build and Push deploy | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-push-deploy: | |
runs-on: ubuntu-latest | |
env: | |
IMAGE_TAG: ${{ github.run_number }} | |
ECR_REPOSITORY: ref-ui | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Configure AWS CLI | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_V2 }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_V2 }} | |
aws-region: us-east-1 | |
- name: Login to Amazon ECR | |
run: | | |
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 151564965346.dkr.ecr.us-east-1.amazonaws.com | |
- name: Build Docker image | |
run: | | |
docker build -t 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} . | |
- name: Push Docker image | |
run: | | |
docker push 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | |
- name: Execute SSH commmands on remote server[52.54.49.247] | |
uses: appleboy/ssh-action@master | |
with: | |
host: 52.54.49.247 | |
username: root | |
key: ${{ secrets.SSH_PRIVATE_KEY_PROD_01 }} | |
port: 60022 | |
script: | | |
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 151564965346.dkr.ecr.us-east-1.amazonaws.com | |
docker stop ref-ui || true | |
docker rm ref-ui || true | |
docker pull 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | |
timeout=300 | |
elapsed=0 | |
while ! docker pull 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | grep -q "Image is up to date"; do | |
sleep 10 | |
elapsed=$((elapsed+10)) | |
if [ "$elapsed" -ge "$timeout" ]; then | |
echo "Timeout waiting for Docker pull." | |
exit 1 | |
fi | |
done | |
docker run -d -p 8080:80 --name ref-ui 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | |
- name: Execute SSH commmands on remote server[34.224.251.142] | |
uses: appleboy/ssh-action@master | |
with: | |
host: 34.224.251.142 | |
username: root | |
key: ${{ secrets.SSH_PRIVATE_KEY_PROD_02 }} | |
port: 60022 | |
script: | | |
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 151564965346.dkr.ecr.us-east-1.amazonaws.com | |
docker stop ref-ui || true | |
docker rm ref-ui || true | |
docker pull 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | |
timeout=300 | |
elapsed=0 | |
while ! docker pull 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} | grep -q "Image is up to date"; do | |
sleep 10 | |
elapsed=$((elapsed+10)) | |
if [ "$elapsed" -ge "$timeout" ]; then | |
echo "Timeout waiting for Docker pull." | |
exit 1 | |
fi | |
done | |
docker run -d -p 8080:80 --name ref-ui 151564965346.dkr.ecr.us-east-1.amazonaws.com/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} |