Merge pull request #54 from DesmondSanctity/event-badging-submit-api #3
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: CI/CD | |
on: | |
push: | |
branches: | |
- "staging" | |
env: | |
IMAGE_NAME: "project_badging_staging" | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Remove old Docker images | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
password: ${{ secrets.PASSWORD }} | |
script: | | |
if docker inspect ${{ env.IMAGE_NAME }} >/dev/null 2>&1; then | |
docker stop ${{ env.IMAGE_NAME }} | |
docker rm ${{ env.IMAGE_NAME }} | |
docker images --filter "reference=${{ env.IMAGE_NAME }}*" -q | xargs docker rmi -f || true | |
fi | |
- name: Build Docker image | |
run: docker build -t ${{ env.IMAGE_NAME }}:${{ github.sha }} . | |
- name: Create image archive | |
run: docker save ${{ env.IMAGE_NAME }}:${{ github.sha }} -o badging-staging.tar | |
- name: Upload image archive using appleboy/scp-action | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
password: ${{ secrets.PASSWORD }} | |
source: badging-staging.tar | |
target: ~/ | |
- name: Extract and load image on droplet | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
password: ${{ secrets.PASSWORD }} | |
script: | | |
docker load -i ~/badging-staging.tar | |
docker run -d \ | |
-p ${{ secrets.PORT }}:${{ secrets.PORT }} \ | |
--env-file /home/${{ secrets.USERNAME }}/staging/.env \ | |
--network host \ | |
--restart=always \ | |
--name ${{ env.IMAGE_NAME }} \ | |
${{ env.IMAGE_NAME }}:${{ github.sha }} |