GitLab.com 정적 웹호스팅 활용

gitlab.com은 private 저장소를 무료로 지원하고 정적 웹호스팅도 지원합니다.
gitlab pages를 활용하여 html 프로젝트 호스팅을 설정하는 기본 내용입니다.

일반 HTML 사이트 호스팅 : https://gitlab.com/pages/plain-html
저장소 master 브랜치 최상위에 아래와 같은 내용의 .gitlab-ci.yml 을 추가하면 public 디렉토리를 기준으로 웹서버가 서비스됩니다.

image: alpine:latest

pages:
  stage: deploy
  script:
  - echo 'Nothing to do...'
  artifacts:
    paths:
    - public
  only:
  - master

nodejs 기반 HTML 빌드 환경에 활용
아래는 gulp를 사용하는 프로젝트의 설정파일입니다.  gulp build task를 실행하고 dist 디렉토리가 배포되는 설정입니다.

image: node:7.7.1

pages:
  cache:
    paths:
    - node_modules/

  script:
  - npm install gulp -g
  - npm install
  - gulp build
  - mv dist public
  artifacts:
    paths:
    - public
  only:
    - master

script: 내용이 명령어를 순차실행하는 부분이므로 프로젝트에 맞게 변경하면 됩니다. grunt, gulp, npm scripts 모두 유사하겠습니다.

위와 같이 CI설정이 완료되면 remote 저장소에 push 될때마다 자동으로 배포가 이뤄집니다.  배포가 완료되면 ‘사용자명or그룹명.gitlab.io/프로젝트명’ URL로 접속할 수 있습니다. 이상으로 간단한 정적 웹호스팅 설정에 대한 정리를 마칩니다.

GitLab CI 소개 : https://about.gitlab.com/features/gitlab-ci-cd/
GitLab Pages 소개 : https://about.gitlab.com/features/pages/