nodejs so파일

nodejs 2021. 9. 10. 14:55

출처 : https://github.com/node-ffi/node-ffi

디렉토리 생성

 

root@server:~/ffi-napi# node -v
v12.19.0

 

 

mkdir ffi-napi

cd ffi-napi

npm install ffi-napi

 

 

factorial.c

#include <stdio.h>


int factorial(int max) {
  int i = max;
  int result = 1;

  while (i >= 2) {
    result *= i--;
  }

  return result;
}

int main(void)
{
        printf("%d\n", factorial(6));
        return 0;
}

공유라이브러리 컴파일

gcc -shared -fpic factorial.c -o libfactorial.so

 

factorial.js

var ffi = require('ffi-napi');
var libfactorial = ffi.Library('./libfactorial', {
  'factorial': [ 'uint64', [ 'int' ] ]
})

if (process.argv.length < 3) {
  console.log('Arguments: ' + process.argv[0] + ' ' + process.argv[1] + ' <max>')
  process.exit()
}

var output = libfactorial.factorial(parseInt(process.argv[2]))

console.log('Your output: ' + output) 

 

실행 

root@server:~/ffi-napi# node factorial.js 3
Your output: 6
root@server:~/ffi-napi# node factorial.js 7
Your output: 5040

'nodejs' 카테고리의 다른 글

DISCORD bot 제작  (0) 2021.10.22
MongoError: Cannot use a session that has ended  (0) 2021.07.20
nodejs 버전 업데이트 하기  (0) 2021.07.15
nodemon 설정 방법  (0) 2020.12.09
axios 전송  (0) 2020.12.08
블로그 이미지

iesay

,
# groups gitlab-runner
gitlab-runner : gitlab-runner



# usermod -a -G root gitlab-runner



# groups gitlab-runner
gitlab-runner : gitlab-runner root

 

'시스템' 카테고리의 다른 글

ipfs 사용법  (0) 2021.12.06
gitlab ci Docker 연동(React)  (0) 2021.11.24
gitlab ci Docker 연동(nodejs)  (2) 2021.08.23
Configuring tzdata Dockerfile  (0) 2021.07.27
방화벽 설정  (0) 2020.10.26
블로그 이미지

iesay

,

구현 환경  : AWS(ubuntu 20.04) , nodejs

 

출처 : 

[GitLab CI] docker gitlab-runner 등록 및 간단 예제 (tistory.com)

https://www.devopsschool.com/blog/setup-docker-service-to-use-insecurehttp-registry-instead-of-https/

https://hihellloitland.tistory.com/65

https://hihellloitland.tistory.com/63

https://otrodevym.tistory.com/474

https://not-to-be-reset.tistory.com/326

https://gitlab.com/gitlab-org/gitlab-runner/-/issues/5026

 

-  Docker  private registry 설치

우분투 초기 이미지 업데이트 레포 찾음 
apt update

도커 컴포저 설치 
apt install docker-compose

도커 레지스트리 설치 
docker pull registry:latest


레지스트리 이미지 구동
docker run --name local-registry -d --restart=always -p 5000:5000 -v /data/registry:/var/lib/registry/docker/registry/v2 registry:latest





빨간색 처럼 private repo 컨테이너 올라가면  실패 재설치

아래 그림처럼 올라가면 성공

 

 

본인이 구축할 private repo IP주소를 작성하면 됩니다.

push시 https만 허용만 가능하여 이렇게 강제로 설정해 줍니다.

 

vi /etc/docker/daemon.json

{

"insecure-registries" : ["13.125.27.25:5000"]

}

 

도커 재 실행 

service docker restart

 

- 방화벽 오픈 (5000, 8900번)

윈도우 도스창에서
telnet  xxx.xxx.xxx.xxx 5000
제대로 접근 가능한지 확인

##############################################################################

-  Gitlab runnuer 설치

 

mkdir -p /opt/gopath/src/gitlab/

cd /opt/gopath/src/gitlab/

vi docker-compose.gitlab.runner.yml 파일 생성

gitlab-runner:
 container_name: gitlab-runner
 image: 'gitlab/gitlab-runner:latest'
 restart: always
 volumes:
  - '/srv/gitlab-runner/config:/etc/gitlab-runner'
  - '/var/run/docker.sock:/var/run/docker.sock'
  - '/usr/bin/docker:/usr/bin/docker'

 

도커 compose파일 실행 

도커 컴포저 실행

docker-compose -f /opt/gopath/src/gitlab/docker-compose.gitlab.runner.yml up -d

컨테이너 실행 확인 
docker container ls

 

gitlab  새로운 project에 파일 3개 생성

Dockerfile

# This file is a template, and might need editing before it works on your project.
FROM node

WORKDIR /usr/src/app

ARG NODE_ENV
ENV NODE_ENV $NODE_ENV

COPY package.json /usr/src/app/
RUN npm install

COPY . /usr/src/app

# replace this with your application's default port
EXPOSE 8900
CMD [ "npm", "start" ]

 

 

index.js

const express = require('express')
const app = express()

app.get('/', function(req, res) {
    res.send('Hello Gitlab!!!!!!안녕하세요!!!!!!!')
})

app.listen(8900, function() {
    console.log('Example app listening on port 8900!')
})
 

 

package.json

{
  "name": "sample",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "express": "^4.17.1"
  }
}

 

 

토큰값 확인 

신용카드 auth도 진행하는데 해외결제 그낭 카드번호만 넣으면 완료

 

 

gitlab-runner 컨테이너에서 등록

아래 보라색 두값만 위 2번에 맞게 쓰시면 되고 Docker 컨테이너 내부 에서 유일하게 진행하는 작업.

그외는 모두 Docker 밖에서 실행

도커 gitlab-runner 컨테이너 실행
docker container exec -it gitlab-runner bash


root@4abec937906f:/# gitlab-runner register -n \
--url https://gitlab.com/ \
--registration-token M9토큰값 \
--description gitlab-runner \
--executor docker \
--docker-image docker:latest \
--docker-volumes /var/run/docker.sock:/var/run/docker.sock

 

Edit를 클릭하여 Tags에  [gitlab-cicd-tag] 작성

 

위에 설정한 tag는 아래 yml파일에서도 사용

 

.gitlab-ci.yml

stages:
  - test
  - build
  - deploy

variables:
  IMAGE_NAME: 13.125.27.25:5000/nodejs-server-test:latest

cache:
  paths:
    - node_modules/
    
test:
  stage: test
  image: node:latest
  script:
    - env
    - npm install

build:
  stage: package
  tags:
    - gitlab-cicd-tag
  image: docker:latest
  services:
    - docker:dind
  stage: build
  script:
    - ls -al
    - docker container ls -a
    - docker build . -t $IMAGE_NAME
    - docker push $IMAGE_NAME
    - docker images | grep '13.125.27.25'

deploy:
  stage: deploy
  tags:
    - gitlab-cicd-tag
  image: docker:latest
  services:
    - docker:dind
  script:
    - docker container ls -a
    - docker container rm -f nodejs-server 
    - docker run -d -p 8900:8900 --name nodejs-server --restart always $IMAGE_NAME
    - docker container ls -a



 

 

 

 

 

gitlab 해당 프로젝트에 파일이 push뒤면 ci pipe라인에서 자동으로 실행 됩니다.

서버 사양은 꽤나 높으면 빠를거 같습니다.

'시스템' 카테고리의 다른 글

gitlab ci Docker 연동(React)  (0) 2021.11.24
gitlab CI_SERVER_TLS_CA_FILE: Permission denied  (0) 2021.08.30
Configuring tzdata Dockerfile  (0) 2021.07.27
방화벽 설정  (0) 2020.10.26
우분투 No space left on device  (0) 2020.06.26
블로그 이미지

iesay

,