Minor #11
Workflow file for this run
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 Pipeline | |
on: | |
push: | |
branches: [master] | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
BACKEND_IMAGE_NAME: allchat-backend | |
FRONTEND_IMAGE_NAME: allchat-frontend | |
SSH_HOST: ${{ secrets.SSH_HOST }} | |
SSH_USER: ${{ secrets.SSH_USER }} | |
SSH_KEY: ${{ secrets.SSH_KEY }} | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@master | |
- name: Build and Push Backend Image | |
run: | | |
docker build -t ${{ env.DOCKER_USERNAME }}/${{ env.BACKEND_IMAGE_NAME }} ./server | |
docker login -u ${{ env.DOCKER_USERNAME }} -p ${{ env.DOCKER_PASSWORD }} | |
docker push ${{ env.DOCKER_USERNAME }}/${{ env.BACKEND_IMAGE_NAME }} | |
- name: Build and Push Frontend Image | |
run: | | |
docker build -t ${{ env.DOCKER_USERNAME }}/${{ env.FRONTEND_IMAGE_NAME }} . | |
docker push ${{ env.DOCKER_USERNAME }}/${{ env.FRONTEND_IMAGE_NAME }} | |
deploy: | |
needs: build-and-push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy to SSH Host | |
env: | |
SSH_KEY: ${{ env.SSH_KEY }} | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$SSH_KEY" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -H ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts | |
ssh ${{ env.SSH_USER }}@${{ env.SSH_HOST }} ' | |
docker pull ${{ env.DOCKER_USERNAME }}/${{ env.BACKEND_IMAGE_NAME }} | |
docker pull ${{ env.DOCKER_USERNAME }}/${{ env.FRONTEND_IMAGE_NAME }} | |
cd allchat | |
docker-compose down | |
docker-compose up -d | |
' |