diff --git a/.github/workflows/azure-deploy-production.yml b/.github/workflows/azure-deploy-production.yml new file mode 100644 index 000000000..65590d930 --- /dev/null +++ b/.github/workflows/azure-deploy-production.yml @@ -0,0 +1,134 @@ +name: Build, test & deploy to Azure Web App + +env: + AZURE_WEBAPP_NAME: funding-frontend # Name set within Azure Web App + REGISTRY: ghcr.io + +on: + push: + branches: + - $default-branch + workflow_dispatch: + +permissions: + contents: read + packages: write + +jobs: + test: + runs-on: ubuntu-latest + services: + db: + image: postgres:11-alpine + ports: ['5432:5432'] + env: + POSTGRES_DB: funding_frontend_test + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 15s + --health-retries 5 + redis: + image: redis + ports: ['6379:6379'] + options: --entrypoint redis-server + + steps: + - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems- + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn config get cacheFolder)" + - uses: actions/cache@v2 + id: yarn-cache + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1.1 + - uses: actions/setup-node@v2-beta + with: + node-version: '16' + - run: npm install -g yarn + - uses: nanasess/setup-chromedriver@master + + - name: Build and run tests + env: + DATABASE_URL: 'postgresql://postgres:postgres@localhost:5432/funding_frontend_test' + BUNDLER_VERSION: 2.3.11 + DOCKER_TLS_CERTDIR: '' + run: | + sudo apt update + sudo apt-get -yqq install postgresql postgresql-client libpq-dev xvfb unzip libcurl4 libcurl3-gnutls libcurl4-openssl-dev + gem install bundler + gem update --system && gem update bundler + yarn install + bundle install --jobs 4 --retry 3 + RAILS_ENV=test bundle exec rake db:setup + RAILS_ENV=test RAILS_DISABLE_TEST_LOG=true bundle exec rspec + + buildx: + runs-on: ubuntu-latest + needs: [test] + if: github.ref == 'refs/heads/master' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ github.token }} + + - name: Lowercase the repository name and username + run: echo "REPOSITORY=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV} + + - name: Build the container image and push it to the registry + uses: docker/build-push-action@v2 + with: + push: true + tags: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ github.sha }} + file: ./Dockerfile + + deploy: + runs-on: ubuntu-latest + needs: [buildx] + if: github.ref == 'refs/heads/master' + + permissions: + contents: none + + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Lowercase the repository name and username + run: echo "REPOSITORY=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV} + + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: ${{ env.AZURE_WEBAPP_NAME }} + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + images: '${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ github.sha }}'