From 6f0f228f93d21e87891cbb9b20f5b0cd642f847c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Thom?= Date: Thu, 19 Sep 2024 11:47:33 +0200 Subject: [PATCH] deploy with azure cli instead --- .github/workflows/deploy.yml | 49 ++++++++++++++++-------------------- Dockerfile | 4 +++ 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 272f9bf..88e1f28 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,8 +1,6 @@ name: Trigger auto deployment -# When this action will be executed on: - # Uncomment the code below for automatically trigger the workflow when detected changes in the main branch push: branches: [main] @@ -15,43 +13,38 @@ permissions: jobs: build-and-deploy: - runs-on: [sb1u] + runs-on: ubuntu-latest steps: - name: Checkout to the branch uses: actions/checkout@v2 - - name: Set up Node.js - uses: actions/setup-node@v4 + - name: Docker Login + uses: docker/login-action@v3 with: - node-version: "20.x" - - - uses: actions/setup-python@v5 - with: - python-version: "3.11" - - - name: Install Azure CLI - run: pip install azure-cli - - # - name: Set up Postgresql with prisma - # run: | - # DATABASE_URL=${{secrets.DATABASE_URL}} npx prisma generate - # DATABASE_URL=${{secrets.DATABASE_URL}} npx prisma migrate deploy + registry: ${{ secrets.ACR_URL }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} - name: Azure Login - uses: azure/login@v1 + uses: azure/login@v2 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - - name: Build and push container image to registry - uses: azure/container-apps-deploy-action@v2 + - name: Build and Push to ACR + uses: docker/build-push-action@v2 with: - appSourcePath: ${{ github.workspace }} - registryUrl: sbukrokeloneacr.azurecr.io - registryUsername: ${{ secrets.CONTAINER_REGISTRY_USERNAME }} - registryPassword: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }} - imageToBuild: sbukrokeloneacr.azurecr.io/krokelo:${{ github.sha }} - dockerfilePath: Dockerfile \ No newline at end of file + push: true + tags: ${{ secrets.ACR_URL }}/krokelo:${{ github.sha }} + file: Dockerfile + + - 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 }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4649b1a..b247ee2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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