I'm trying to run my nodejs app on gitlab pages. I use a gitlab-ci.yml file for this where I deploy and run the nodejs app. Unfortunately the pipeline kills the process after 1 hour because the pipeline thinks running the nodejs app is part of the build script. I have two questions:
- Can you run a nodejs app on gitlab pages?
- If so, what is the best way to start the app?
Below you find the gitlab-ci.yml file.
Thanks!
image: node:latest
stages:
- build
cache:
paths:
- node_modules/
install_dependencies:
stage: build
script:
- npm install
- npm install -g nodemon
- NODE_ENV=production nodemon app.js
artifacts:
paths:
- node_modules/
Can you run a nodejs app on gitlab pages?
No! Gitlab pages allow you to host only static websites: https://about.gitlab.com/product/pages/
If so, what is the best way to start the app?
If your app is static, try to use a static site generator! If you wanna play with nodejs, try other hosting platforms like heroku or clever cloud
Related
I'm trying to use the SSR with AWS Amplify but when I activate the Node.js and change the output type to server. When I deploy to server I got an 404 error page.
I tried to build the project and I have to run two npm commands: npm run build and after that the npm run server. But the deploy is not working.
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
postBuild:
commands:
- npm run server
artifacts:
baseDirectory: /dist
files:
- '**/*'
cache:
paths:
- node_modules/**/*
Astro has, adapters for each SSR cloud solution, and I haven't seen AWS listed
you could use vercel or cloudflare
and install the adapter of those server
npx astro add cloudflare
on your option I think amplify is needing for nodejs adapter and its already exist
use this instead
npx astro add node
I have a repo which attempts to serve an index.html file using
the NPM serve module in a GitHub action.
Here's what the action looks like (.github/workflows/deploy.yml):
name: test-serve-deploy
on: [push]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout#v3
- run: echo "Clone complete"
- name: install
run: |
npm install
- name: serve
run: |
npm run serve
- run: echo "Status ${{ job.status }}"
I understand that the content in my repo is just an index.html file and could be served statically with GitHub Pages, but this is just a test repo I'm using to understand how GitHub actions work.
When the action runs, it predictably hangs on the npm run serve:
However, this URL returns a 404: http://jonbri.github.io/test-serve:3000
I'm sure I'm missing something fundamental about how these actions/runners work.
My goal is to have the GitHub repo not only deploy but also serve a Node.js app.
What steps would I need to take to get this working?
Github runners are ephemeral. They just run the commands you provide and exit.
They cannot serve pages. If you want to serve content, you might want to use your github runner to deploy your content to a provider such as netlify or aws s3, lambda etc.
image: node:9.2.0
stages:
- build
build:
stage: build
script:
- set NODE_ENV=production
- npm install
- npm run transpile
- ls
- cd dist-server
- ls
- node /bin/www
#- npm run prod
artifacts:
expire_in: 1 day
paths:
- dist/
Above is my yaml file for ci can anyone share how to deploy this on the linux Azure Web App.
There is no out-of-the-box solution to deploy to Azure using Gitlab.
What you can do in your Gitlab pipeline is the following proces:
Build docker container
Push docker container to Gitlab Container Registry (is included in your Gitlab Repository)
Run a curl command to trigger the Azure App Service webhook to update
You can host this Docker container in Azure (after creating the App Service, you can find the webhook url in the Deployment settings)
I already did CI, but now I want to deploy to my server. My server is the same machine where I do CI, but I do CI in docker-executor. So I can't have acces to server folders to update production.
There is my script:
image: node:9.11.2
cache:
paths:
- node_modules/
before_script:
- npm install
stages:
- test
- deploy
test:
stage: test
script:
- npm run test
deploy:
stage: deploy
script:
#here I want to go to /home/projectFolder and make git pull, npm i, npm start
# but I can't beause I run CI in docker-environment which hasn't acces to my server's dirictories.
First of all you should consider using gitlab auto cicd ( or use it as a base to customize if you dont want to use kubernetes)
You have multiple way to do so but the simplest way should be to use an alpine image and
- install ssh (if necessary)
- load your private ssh key ( from pipeline secrets)
- run your npm commands through ssh.
The cleanest way would be :
- generating adding a valid Dockerfile to your project
- adding docker image generation for each commit on master (in your pipeline)
- Adding docker rm running image (in your pipeline)
- Adding docker run the newly generated image (in your pipeline) (by sharing your docker volume)
- Make nginx redirect to your container.
I can give more detailed advice depending on what you decide to do.
Hoping i helped.
I am developing a desktop app on a Linux machine. The code is hosted on GitLab.com. I'd like a sample gitlab-ci.yml on building the app for Windows. I'm out of ideas on how to go about this, any assistance will be appreciated.
The build steps depends on the library you are using to build the electron app. Here is a sample using electron-builder
// .gitlab-ci.yml
stages:
- build
build:
image: electronuserland/builder:wine
stage: build
script:
- yarn
- yarn dist:win
artifacts:
expire_in: 30 days
paths:
- ./dist/
only:
- master
// package.json
{
...
"scripts": {
...
"dist:win": "electron-builder -w",
}
}
I feel this question is more related to electron itself rather than GitLab CI. In the runner config you perform all tasks you'd normally perform while developing the app locally. So you should put all the stuff you usually put into your build tasks locally into the CI config.