diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml index ccf7319..3926411 100644 --- a/.github/workflows/build-deploy.yml +++ b/.github/workflows/build-deploy.yml @@ -3,82 +3,82 @@ name: Build and Deploy Code on: [push, pull_request] jobs: - # build_and_test: - # environment: - # name: testing - # env: - # PG_USERNAME: ${{secrets.PG_USERNAME}} - # PG_PASSWORD: ${{secrets.PG_PASSWORD}} - # PG_HOST: ${{secrets.PG_HOST}} - # PG_PORT: ${{secrets.PG_PORT}} - # PG_DATABASE: ${{secrets.PG_DATABASE}} - # SECRET_KEY: ${{secrets.SECRET_KEY}} - # ALGORITHM: ${{secrets.ALGORITHM}} - # ACCESS_TOKEN_EXPIRE_MINUTES: ${{secrets.ACCESS_TOKEN_EXPIRE_MINUTES}} - # services: - # postgres: - # image: postgres - # env: - # POSTGRES_PASSWORD: ${{secrets.PG_PASSWORD}} - # POSTGRES_DB: ${{secrets.PG_DATABASE}}_test - # options: >- - # --health-cmd pg_isready - # --health-interval 10s - # --health-timeout 5s - # --health-retries 5 - # ports: - # - 5432:5432 - # runs-on: ubuntu-latest - # steps: - # - name: Pull the git repository - # uses: actions/checkout@v4 - # - name: Install python version 3.11.6 - # uses: actions/setup-python@v4 - # with: - # python-version: '3.11.6' - # - name: Update pip - # run: python -m pip install --upgrade pip - # - name: Install dependencies - # run: pip install -r requirements.txt - # - name: Run tests with Pytest - # run: | - # pip install pytest - # pytest -v -s --disable-warnings + build_and_test: + environment: + name: testing + env: + PG_USERNAME: ${{secrets.PG_USERNAME}} + PG_PASSWORD: ${{secrets.PG_PASSWORD}} + PG_HOST: ${{secrets.PG_HOST}} + PG_PORT: ${{secrets.PG_PORT}} + PG_DATABASE: ${{secrets.PG_DATABASE}} + SECRET_KEY: ${{secrets.SECRET_KEY}} + ALGORITHM: ${{secrets.ALGORITHM}} + ACCESS_TOKEN_EXPIRE_MINUTES: ${{secrets.ACCESS_TOKEN_EXPIRE_MINUTES}} + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: ${{secrets.PG_PASSWORD}} + POSTGRES_DB: ${{secrets.PG_DATABASE}}_test + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + runs-on: ubuntu-latest + steps: + - name: Pull the git repository + uses: actions/checkout@v4 + - name: Install python version 3.11.6 + uses: actions/setup-python@v4 + with: + python-version: '3.11.6' + - name: Update pip + run: python -m pip install --upgrade pip + - name: Install dependencies + run: pip install -r requirements.txt + - name: Run tests with Pytest + run: | + pip install pytest + pytest -v -s --disable-warnings - # - name: Login to Docker Hub - # uses: docker/login-action@v3 - # with: - # username: ${{ secrets.DOCKER_HUB_USERNAME }} - # password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - # - name: Set up Docker Buildx - # uses: docker/setup-buildx-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - # - name: Build and push Docker image - # uses: docker/build-push-action@v5 - # with: - # context: . - # file: ./Dockerfile - # push: true - # tags: ${{ secrets.DOCKER_HUB_USERNAME }}/sm-fastapi:latest - # cache-from: type=local,src=/tmp/.buildx-cache - # cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/sm-fastapi:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max deploy: environment: name: production runs-on: ubuntu-latest - # needs: [build_and_test] + needs: [build_and_test] steps: - name: Pull the git repository uses: actions/checkout@v4 - # - name: Deploy to Heroku - # uses: akhileshns/heroku-deploy@v3.12.14 - # with: - # heroku_api_key: ${{secrets.HEROKU_API_KEY}} - # heroku_app_name: ${{secrets.HEROKU_APP_NAME}} - # heroku_email: ${{secrets.HEROKU_EMAIL}} + - name: Deploy to Heroku + uses: akhileshns/heroku-deploy@v3.12.14 + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: ${{secrets.HEROKU_APP_NAME}} + heroku_email: ${{secrets.HEROKU_EMAIL}} - name: Deploy to Ubuntu VM uses: appleboy/ssh-action@v1.0.0