[Sprint 6][Task 5] real email client #34
This file contains hidden or 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: Build, Test and Deploy to Prod | |
| # Trigger the workflow when changes are pushed to the main branch | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| env: | |
| SQLX_OFFLINE: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| # Docker Hub image | |
| image: postgres:15.2-alpine | |
| # Environment variables scoped only for the `postgres` element | |
| env: | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} | |
| POSTGRES_DB: postgres | |
| # Opens tcp port 5432 on the host and service container | |
| ports: | |
| - 5432:5432 | |
| redis: | |
| image: redis:7.0-alpine | |
| ports: | |
| - 6379:6379 | |
| steps: | |
| # Checkout code from the repository | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| # Cache dependencies to speed up build times | |
| - name: Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| app-service/.cargo | |
| app-service/target/ | |
| auth-service/.cargo | |
| auth-service/target/ | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: ${{ runner.os }}-cargo- | |
| - name: Install Rust | |
| run: rustup update stable && rustup default stable | |
| - name: Build and test app-service code | |
| working-directory: ./app-service | |
| run: | | |
| cargo build --verbose | |
| cargo test --verbose | |
| - name: Build and test auth-service code | |
| working-directory: ./auth-service | |
| run: | | |
| export JWT_SECRET=secret | |
| cargo build --verbose | |
| cargo test --verbose | |
| # Set up Docker Buildx for multi-platform builds | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push Docker images | |
| uses: docker/[email protected] | |
| with: | |
| push: true | |
| files: | | |
| compose.yml | |
| compose.override.yml | |
| set: | | |
| *.cache-from=type=gha | |
| *.cache-to=type=gha,mode=max | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v1 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Install sshpass | |
| run: sudo apt-get install sshpass | |
| - name: Copy compose.yml to droplet | |
| run: sshpass -v -p '${{ secrets.DROPLET_PASSWORD }}' scp -o StrictHostKeyChecking=no compose.yml root@${{ vars.DROPLET_IP }}:~ | |
| - name: Deploy | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ vars.DROPLET_IP }} | |
| username: root | |
| password: ${{ secrets.DROPLET_PASSWORD }} | |
| script: | | |
| cd ~ | |
| export JWT_SECRET=${{ secrets.JWT_SECRET }} | |
| export AUTH_SERVICE_IP=${{ vars.DROPLET_IP }} | |
| export POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} | |
| export POSTMARK_AUTH_TOKEN=${{ secrets.POSTMARK_AUTH_TOKEN }} | |
| docker compose down | |
| docker compose pull | |
| docker compose up -d |