Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

node.js - Build Node/Express using Github Actions and deploy to Azure Web App

I have a Node/Express project which use the azure-ts-node-starter project. By default it compiles Typescript from /src into /dist (package.json below)

I'd like to delpoy to Azure every time I upload to the master branch of my Github repo but I'm not sure what to do with src/dist folders.

  • Should I build on my PC, then commit everything, which I think would give me the choice of using Azure deployment center OR Github actions (not sure of the difference yet) to deploy the whole project or...

  • Could I put the /dist folder in gitignore and only upload src files, then somehow build it every time I push to master?

If I do the second option, would it just deploy the contents of the /dist folder and not send all the source files to Azure? That would seem sensible but wouldn't it need some files from the main directory, such as the package.json file so that it knows how to start?

Apologies if this question isn't well formed, I'm not sure what I need to ask. I guess the questions is what is the standard way commit and deploy projects which use a dist directory?

Here are the scripts in the package.json file.

    "scripts": {
        "build": "npm run build-ts && npm run copy-static-assets",
        "build-ts": "tsc",
        "copy-static-assets": "ts-node copyStaticAssets.ts",
        "serve": "node dist/server.js",
        "start": "npm run serve",
        "watch": "concurrently -k -p "[{name}]" -n "TypeScript,Node" -c "cyan.bold,green.bold" "npm run watch-ts" "npm run watch-node"",
        "watch-node": "nodemon dist/server.js",
        "watch-ts": "tsc -w"
    },
question from:https://stackoverflow.com/questions/65850014/build-node-express-using-github-actions-and-deploy-to-azure-web-app

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Not answering directly what you want, but in the last 3 years I had so many issues with running NodeJs on Azure that I could only rely on containers to actually have the nodeJs app running smoothly...

for that, my GitHub action was like this

.github/workflows/azure.yml

name: Azure deploy
on:
  push:
    branches:
      - master

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest

    steps:
    # checkout the repo
    - name: 'Checkout GitHub Action' 
      uses: actions/checkout@master
    
    - name: 'Login via Azure CLI'
      uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}
    
    - uses: azure/docker-login@v1
      with:
        login-server: my_domain.azurecr.io
        username: ${{ secrets.REGISTRY_USERNAME }}
        password: ${{ secrets.REGISTRY_PASSWORD }}
    
    - run: |
        docker build . -t my_domain.azurecr.io/teamcalendar:latest
        docker push my_domain.azurecr.io/teamcalendar:latest

Dockerfile

FROM node:lts-alpine

WORKDIR /usr/app

COPY package*.json ./
RUN npm install
COPY . .

CMD ["npm", "start"]

more info on MS Docs


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...