Skip to content

Commit

Permalink
Merge pull request #2 from sparebank1utvikling/dev
Browse files Browse the repository at this point in the history
Add lint, build, deploy jobs to github action
  • Loading branch information
havardthom authored Sep 19, 2024
2 parents 7d19f90 + 75ecd9e commit b73eab5
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 44 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Continuous Integration and Continuous Delivery

on:
push:

permissions:
id-token: write
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout to the branch
uses: actions/checkout@v4

- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list

- name: Install dependencies
run: npm install --prefer-offline

# - name: Typecheck
# run: npm run typecheck

- name: Lint ESLint
run: npm run lint

- name: Lint Prettier
run: npm run prettier

build:
runs-on: ubuntu-latest
steps:
- name: Checkout to the branch
uses: actions/checkout@v4

- name: Docker Login
uses: docker/login-action@v3
with:
registry: ${{ secrets.ACR_URL }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}

- name: Build and Push to ACR
uses: docker/build-push-action@v2
with:
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ secrets.ACR_URL }}/krokelo:${{ github.sha }}
file: Dockerfile
build-args: |
DATABASE_URL=${{ secrets.DATABASE_URL }}
deploy:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
needs: [lint, build]
steps:
- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Redeploy Azure Container App

run: |
az containerapp revision copy \
--name krokelo \
--resource-group sbu-public-krokelo-nww-nea-rg \
--cpu 1 \
--memory 2.0 \
--image ${{ secrets.ACR_URL }}/krokelo:${{ github.sha }}
44 changes: 0 additions & 44 deletions .github/workflows/deploy.yml

This file was deleted.

4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ RUN npx prisma generate
ADD . .
RUN npm run build

# Run migrations
ARG DATABASE_URL
RUN npm run deploy:db

# Finally, build the production image with minimal footprint
FROM base

Expand Down

0 comments on commit b73eab5

Please sign in to comment.