DEAR-136: add delete user #164
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 | |
on: | |
push: | |
branches: ["*"] | |
pull_request: | |
branches: ["main"] | |
workflow_dispatch: | |
jobs: | |
build_and_test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'adopt' | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 | |
- name: Build with Gradle | |
run: ./gradlew build | |
env: | |
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} | |
JWT_SECRET: ${{ secrets.JWT_SECRET }} | |
- 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-backend | |
LOWER_REPO_NAME=$(echo $REPO_NAME | tr '[A-Z]' '[a-z]') | |
docker build -t $LOWER_REPO_NAME:latest . | |
docker push $LOWER_REPO_NAME:latest | |
deploy: | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
needs: build_and_test | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup SSH | |
uses: webfactory/ssh-agent@v0.5.3 | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Deploy to server | |
env: | |
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} | |
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 backend nginx && | |
docker-compose rm backend nginx && | |
docker pull ghcr.io/24fsiit16/dear-dev-backend:latest | |
JWT_SECRET=${{ secrets.JWT_SECRET }} DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }} docker-compose up -d' | |
EOF | |
- name: cleanup | |
run: rm -rf ~/.ssh |