Merge pull request #3 from LainForge/feat/project-blogs #25
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: build on docker hub and deploy to aws | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout code | |
uses: actions/checkout@v2 | |
- name: set up docker buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: log in to docker hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: build and push docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: ./ | |
push: true | |
dockerfile: ./Dockerfile | |
tags: rohansinghagent/lainforge-home:latest | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout code | |
uses: actions/checkout@v2 | |
- name: log in to docker hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: set permissions for private-key | |
run: | | |
echo "${{ secrets.AWS_PRIVATE_KEY }}" > key.pem | |
chmod 600 key.pem | |
- name: Download new docker compose file | |
run: | | |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@18.140.65.193 'curl -LJO https://github.com/LainForge/LainForge.github.io/raw/main/.github/compose/production.yaml' | |
- name: Bring down already running docker containers | |
run: | | |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@18.140.65.193 'docker kill $(docker ps -q)' | |
- name: Delete old images | |
run: | | |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@18.140.65.193 'docker rm $(docker ps -aq --filter status="exited")' | |
- name: Pull latest images from docker compose | |
run: | | |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@18.140.65.193 'docker-compose -f production.yaml pull' | |
- name: Restart using docker compose | |
run: | | |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@18.140.65.193 'docker-compose -f production.yaml up -d' |