Skip to content

Minor

Minor #329

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [main]
workflow_dispatch:
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: copy file via ssh
uses: garygrossgarten/github-action-scp@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
privateKey: ${{ secrets.SSH_KEY }}
local: "docker-compose.yml"
remote: "allchat/docker-compose.yml"
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run test
- name: Build and Push Backend Image
if: success()
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 }}
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
# - name: Build and Push Backend Image (arm64)
# run: |
# docker buildx build \
# --platform linux/arm64 \
# --output "type=image,push=true" \
# --tag ${{ env.DOCKER_USERNAME }}/${{ env.BACKEND_IMAGE_NAME }}:arm64 \
# ./server
# - name: Build and Push Frontend Image (arm64)
# run: |
# docker buildx build \
# --platform linux/arm64/v8 \
# --output "type=image,push=true" \
# --tag ${{ env.DOCKER_USERNAME }}/${{ env.FRONTEND_IMAGE_NAME }}:arm64 \
# .
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
'