Update pipeline #170
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 yappi | |
on: | |
push: | |
branches: ['*'] | |
pull_request: | |
branches: ['main'] | |
workflow_dispatch: | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '22.4.1' | |
- name: Clear npm cache | |
run: npm cache clean --force | |
- name: Install dependencies | |
run: npm install | |
- name: Run Prettier | |
run: npm run format | |
- name: Run ESLint | |
run: npm run lint | |
build_and_publish: | |
runs-on: ubuntu-latest | |
# if: github.ref == 'refs/heads/main' | |
needs: test | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '22.4.1' | |
- name: Install dependencies | |
run: npm install | |
- name: Build app | |
run: npm run build | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to GitHub Container Registry | |
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin | |
- name: Build and push Docker image | |
run: | | |
REPO_NAME=ghcr.io/${{ github.repository_owner }}/dear-dev-frontend | |
LOWER_REPO_NAME=$(echo $REPO_NAME | tr '[A-Z]' '[a-z]') | |
docker build \ | |
--build-arg SECRET_KEY_NEXT_AUTH=${{ secrets.SECRET_KEY_NEXT_AUTH }} \ | |
--build-arg NEXT_PUBLIC_API_URL=http://yappi.ch \ | |
-t $LOWER_REPO_NAME:latest . | |
docker push $LOWER_REPO_NAME:latest | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build_and_publish | |
name: deploy image | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup SSH | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Deploy to server | |
env: | |
JWT_SECRET: ${{ secrets.JWT_SECRET }} | |
SSH_USER: ${{ secrets.SSH_USER }} | |
SSH_HOST: ${{ secrets.SSH_HOST }} | |
SSH_ITALIAN_PASSWORD: ${{ secrets.SSH_ITALIAN_PASSWORD }} | |
SSH_ITALIAN_USER: ${{ secrets.SSH_ITALIAN_USER }} | |
run: | | |
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} <<'EOF' | |
echo '${{ secrets.SSH_ITALIAN_PASSWORD }}' | sudo -S su - ${{ secrets.SSH_ITALIAN_USER }} -c ' | |
cd ~/yappi && | |
docker-compose stop frontend && | |
docker-compose rm frontend && | |
docker pull ghcr.io/24fsiit16/dear-dev-frontend:latest | |
docker-compose up -d frontend' | |
EOF | |
- name: cleanup | |
run: rm -rf ~/.ssh |