Merge pull request #90 from Prodeko/e2e #108
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: Build and deploy | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: CI environment | |
type: environment | |
required: true | |
permissions: | |
id-token: write | |
env: | |
AZURE_CORE_OUTPUT: none | |
jobs: | |
build: | |
environment: Production | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:14-alpine | |
env: | |
POSTGRES_PASSWORD: ci-password | |
POSTGRES_DB: vaalikoppi | |
POSTGRES_USER: vaalikoppi | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 6s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
- 5432:5432 | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Log in to Azure | |
uses: Azure/login@v1 | |
with: | |
client-id: ${{ secrets.CLIENT_ID }} | |
tenant-id: ${{ secrets.TENANT_ID }} | |
allow-no-subscriptions: true | |
- name: Docker login to ACR | |
run: az acr login --name ${{ secrets.REGISTRY_NAME }} | |
- uses: docker/setup-buildx-action@v3 | |
with: | |
driver-opts: | | |
network=host | |
- name: Build and push image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ${{ secrets.REGISTRY_LOGIN_SERVER }}/vaalikoppi/vaalikoppi:${{ github.sha }} | |
# There is intentionally no scope on the cache due to github's cache access restrictions. | |
# Both the release and debug file will now be stored in the same location. | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-args: | | |
"DATABASE_URL=postgres://vaalikoppi:ci-password@localhost:5432/vaalikoppi" | |
allow: | | |
network.host | |
security.insecure | |
network: host | |
- name: Azure logout | |
run: | | |
az logout | |
e2e: # This step is here for redundancy to protect prod from the inevitable force push to main :D | |
environment: Production | |
runs-on: ubuntu-latest | |
needs: build | |
services: | |
postgres: | |
image: postgres:14-alpine | |
env: | |
POSTGRES_PASSWORD: ci-password | |
POSTGRES_DB: vaalikoppi | |
POSTGRES_USER: vaalikoppi | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 6s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
- 5432:5432 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: Azure/login@v2 | |
with: | |
client-id: ${{ secrets.CLIENT_ID }} | |
tenant-id: ${{ secrets.TENANT_ID }} | |
allow-no-subscriptions: true | |
- name: Install dependencies | |
run: npm ci | |
- name: Install Playwright browsers | |
run: npx playwright install --with-deps | |
- name: Docker login to ACR | |
run: az acr login --name ${{ secrets.REGISTRY_NAME }} | |
- name: Run vaalikoppi and tests | |
run: | | |
docker run \ | |
-e PORT=80 \ | |
-e DATABASE_URL='postgres://vaalikoppi:ci-password@localhost:5432/vaalikoppi' \ | |
-e HMAC_KEY='1234' \ | |
-e ADMIN_PASSWORD='CI_ADMIN_PASSWORD' \ | |
--name vaalikoppi \ | |
--network host \ | |
-d \ | |
${{ secrets.REGISTRY_NAME }}.azurecr.io/vaalikoppi/vaalikoppi:${{ github.sha }} && \ | |
docker ps && \ | |
docker container logs vaalikoppi && \ | |
wget http://localhost:80 || \ | |
docker ps && \ | |
docker container logs vaalikoppi && \ | |
ADMIN_PASSWORD='CI_ADMIN_PASSWORD' PORT=80 npx playwright test | |
deploy: | |
environment: Production | |
runs-on: ubuntu-latest | |
needs: e2e | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Log in to Azure | |
uses: Azure/login@v1 | |
with: | |
client-id: ${{ secrets.CLIENT_ID }} | |
tenant-id: ${{ secrets.TENANT_ID }} | |
allow-no-subscriptions: true | |
- name: Docker login to ACR | |
run: az acr login --name ${{ secrets.REGISTRY_NAME }} | |
- name: Deploy from ACR | |
run: | | |
az webapp config container set \ | |
--container-image-name ${{ secrets.REGISTRY_NAME }}.azurecr.io/vaalikoppi/vaalikoppi:${{ github.sha }} \ | |
--container-registry-url https://${{ secrets.REGISTRY_NAME }}.azurecr.io \ | |
--subscription ${{ secrets.SUBSCRIPTION }} \ | |
--resource-group vaalikoppi_group \ | |
--name vaalikoppi | |
- name: Azure logout | |
run: | | |
az logout |