Autodeployment #123
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: Autodeployment | |
on: | |
schedule: | |
- cron: '0 08 * * 1' # kl 09 hver mandag | |
env: | |
IMAGE: ghcr.io/${{ github.repository }}/send-inn-frontend:prod_${{ github.sha }} | |
CI: true | |
TZ: Europe/Oslo | |
AUTODEPLOY_ACTIVE: ${{ secrets.AUTODEPLOY_ACTIVE }} # autodeploy only runs if the secret is set to true | |
jobs: | |
build-and-test: | |
name: Build and Test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
cache: 'npm' | |
registry-url: 'https://npm.pkg.github.com' | |
scope: '@navikt' | |
- name: Install dependencies | |
run: npm ci | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build with mock | |
run: npm run build:mock | |
- uses: cypress-io/[email protected] | |
with: | |
install: false | |
spec: cypress/e2e/*.cy.js | |
start: npm run start:with:test | |
wait-on: 'http://localhost:3000/sendinn/api/isAlive' | |
config: video=false | |
config-file: cypress.config.ts | |
build-and-push: | |
name: Build and push Docker container | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
cache: 'npm' | |
registry-url: 'https://npm.pkg.github.com' | |
scope: '@navikt' | |
- name: Install dependencies | |
run: npm ci | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set environment variables (prod) | |
run: cp environments/prod.env .env | |
- name: Build | |
env: | |
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
run: npm run build | |
- name: Build and publish Docker image | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
if: env.AUTODEPLOY_ACTIVE == 'true' | |
run: | | |
docker login ghcr.io -u ${GITHUB_REPOSITORY} -p ${GITHUB_TOKEN} | |
docker build --tag ${IMAGE} . | |
docker push ${IMAGE} | |
deploy-prod: | |
name: Deploy to prod | |
needs: [build-and-test, build-and-push] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: nais/deploy/actions/deploy@v1 | |
if: env.AUTODEPLOY_ACTIVE == 'true' | |
env: | |
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | |
DRY_RUN: false | |
PRINT_PAYLOAD: true | |
CLUSTER: prod-gcp | |
RESOURCE: .nais/nais.yml | |
VAR: app_version=${{ github.sha }} |