name: deploy-socialize on: push: branches: - main jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install SSH client run: apt-get update && apt-get install -y openssh-client - name: Test backend env: DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} DEPLOY_USER: ${{ secrets.DEPLOY_USER }} DEPLOY_SSH_PRIVATE_KEY_B64: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY_B64 }} run: | mkdir -p ~/.ssh printf '%s' "$DEPLOY_SSH_PRIVATE_KEY_B64" | base64 -d > ~/.ssh/deploy_key chmod 600 ~/.ssh/deploy_key tar \ --exclude=.git \ --exclude='**/bin' \ --exclude='**/obj' \ --exclude='**/node_modules' \ --exclude=frontend/dist \ --exclude=frontend/dist-ssr \ -czf - . | ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=accept-new "$DEPLOY_USER@$DEPLOY_HOST" \ "set -Eeuo pipefail workdir=/tmp/socialize-ci/${{ gitea.sha }} rm -rf \"\$workdir\" mkdir -p \"\$workdir\" tar -xzf - -C \"\$workdir\" cd \"\$workdir\" find . -type d \( -name bin -o -name obj \) -prune -exec rm -rf {} + dotnet restore backend/Socialize.slnx dotnet test backend/Socialize.slnx --no-restore" image: needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install Docker CLI run: apt-get update && apt-get install -y docker.io - name: Login to Gitea container registry env: REGISTRY_USER: ${{ secrets.REGISTRY_USER }} REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} run: printf '%s' "$REGISTRY_PASSWORD" | docker login git.mapachotes.com -u "$REGISTRY_USER" --password-stdin - name: Build images run: | docker build \ -t git.mapachotes.com/jbourdon/socialize-api:${{ gitea.sha }} \ -t git.mapachotes.com/jbourdon/socialize-api:latest \ -f backend/src/Socialize.Api/Dockerfile . docker build \ --build-arg VITE_API_URL=/api \ -t git.mapachotes.com/jbourdon/socialize-web:${{ gitea.sha }} \ -t git.mapachotes.com/jbourdon/socialize-web:latest \ -f frontend/Dockerfile . - name: Push images run: | docker push git.mapachotes.com/jbourdon/socialize-api:${{ gitea.sha }} docker push git.mapachotes.com/jbourdon/socialize-api:latest docker push git.mapachotes.com/jbourdon/socialize-web:${{ gitea.sha }} docker push git.mapachotes.com/jbourdon/socialize-web:latest deploy: needs: image runs-on: bookworm steps: - name: Install SSH client run: apt-get update && apt-get install -y openssh-client - name: Deploy on sobina env: DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} DEPLOY_USER: ${{ secrets.DEPLOY_USER }} DEPLOY_SSH_PRIVATE_KEY_B64: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY_B64 }} run: | mkdir -p ~/.ssh printf '%s' "$DEPLOY_SSH_PRIVATE_KEY_B64" | base64 -d > ~/.ssh/deploy_key chmod 600 ~/.ssh/deploy_key ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=accept-new "$DEPLOY_USER@$DEPLOY_HOST" \ 'cd /srv/prod/socialize && ./deploy.sh'