Skip to content
Snippets Groups Projects
Commit 91481491 authored by Hoat Le's avatar Hoat Le
Browse files

get this work with gitlab-ci

parent c08323ad
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
# how to use: $ export $(cat .env | grep -v ^# | xargs) # how to use: $ export $(cat .env | grep -v ^# | xargs)
# for package.json # for package.json
PROJECT_NAME=angular-boilerplate PROJECT_NAME=angular-helloworld
PROJECT_VERSION=0.2.0-SNAPSHOT PROJECT_VERSION=0.2.0-SNAPSHOT
# for docker-compose.yml and docker-compose.prod.yml # for docker-compose.yml and docker-compose.prod.yml
DOCKER_IMAGE_DEV=teracy/angular-boilerplate:dev_develop DOCKER_IMAGE_DEV=teracy/angular-cli:1.0.0-rc.2
DOCKER_IMAGE_PROD=teracy/angular-boilerplate:develop DOCKER_IMAGE_PROD=teracy/angular-hello-world:develop
# for nginx-proxy to use domains instead of ports # for nginx-proxy to use domains instead of ports
# see: https://github.com/teracyhq/angular-boilerplate/issues/31 # see: https://github.com/teracyhq/angular-boilerplate/issues/31
......
# This file is a template, and might need editing before it works on your project.
# Official docker image.
image: docker:latest
services:
- docker:dind
variables:
# see https://gitlab.com/gitlab-org/gitlab-ce/issues/17861#note_12991518
DOCKER_DRIVER: overlay
stages:
- build
# - deploy
# variables:
# HEROKU_USER_NAME: _
# HEROKU_REGISTRY: registry.heroku.com
# HEROKU_IMAGE_PROCESS_TYPE: web
# HEROKU_STAGING_IMAGE: $HEROKU_REGISTRY/$HEROKU_STAGING_APP_NAME/$HEROKU_IMAGE_PROCESS_TYPE
# HEROKU_PROD_IMAGE: $HEROKU_REGISTRY/$HEROKU_PROD_APP_NAME/$HEROKU_IMAGE_PROCESS_TYPE
before_script:
- apk add --no-cache py-pip
- pip install docker-compose
- docker-compose --version
# convert / to -, remove # character from docker tag name to make it a valid name
- export IMG_TAG=`if [ "$CI_BUILD_REF_NAME" == "master" ]; then echo "latest"; else echo $CI_BUILD_REF_NAME | sed -e 's/[\/]/-/g' | sed -e 's/[\#]//g'; fi`
- export DOCKER_IMAGE_PROD=$CI_REGISTRY_IMAGE:$IMG_TAG
- docker login -u "gitlab-ci-token" -p "$CI_BUILD_TOKEN" $CI_REGISTRY
- export CI_BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
- export CI_BUILDER=gitlab-ci
- cp .env.example .env
build-verify:
stage: build
script:
- docker-compose run --rm dev yarn
# run and check the dev container
- docker-compose run --rm dev yarn run lint
- docker-compose run --rm dev ng test --browsers Chrome_no_sandbox -w false
- docker-compose run --rm dev yarn run e2e
# build, run and check the prod image
- docker-compose run --rm dev ng build --prod
- docker-compose -f docker-compose.prod.yml build prod
- docker push $DOCKER_IMAGE_PROD
...@@ -16,28 +16,24 @@ before_install: ...@@ -16,28 +16,24 @@ before_install:
- docker --version - docker --version
- docker-compose --version - docker-compose --version
before_script: before_script:
- cp .env.example .env
- export $(cat .env | grep -v ^# | xargs)
- export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH | sed -e 's/[\/]/-/g' | sed -e 's/[\#]//g'; fi` - export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH | sed -e 's/[\/]/-/g' | sed -e 's/[\#]//g'; fi`
- export DOCKER_IMAGE_DEV=$CI_REGISTRY_IMAGE:dev_$TAG
- export DOCKER_IMAGE_PROD=$CI_REGISTRY_IMAGE:$TAG - export DOCKER_IMAGE_PROD=$CI_REGISTRY_IMAGE:$TAG
- export CI_BUILD_ID=$TRAVIS_BUILD_ID - export CI_BUILD_ID=$TRAVIS_BUILD_ID
- export CI_BUILD_REF=$TRAVIS_COMMIT - export CI_BUILD_REF=$TRAVIS_COMMIT
- export CI_BUILD_REF_NAME=$TRAVIS_BRANCH - export CI_BUILD_REF_NAME=$TRAVIS_BRANCH
- export CI_PROJECT_NAME=$TRAVIS_REPO_SLUG - export CI_PROJECT_NAME=$TRAVIS_REPO_SLUG
- chmod +x setup.sh - export CI_BUILDER=travis-ci
- ./setup.sh - cp .env.example .env
script: script:
- docker-compose build --pull - docker-compose run --rm dev yarn
# run and check the dev container # run and check the dev container
- docker-compose run --rm dev npm run lint - docker-compose run --rm dev yarn run lint
- docker-compose run --rm dev ng test --browsers Chrome_no_sandbox -w false - docker-compose run --rm dev ng test --browsers Chrome_no_sandbox -w false
- docker-compose run --rm dev npm run e2e - docker-compose run --rm dev yarn run e2e
# build, run and check the prod image # build, run and check the prod image
- sudo rm -rf .com.google.Chrome*
- docker-compose run --rm dev ng build --prod - docker-compose run --rm dev ng build --prod
- docker-compose -f docker-compose.prod.yml build --pull # sudo required for ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?
- sudo docker-compose -f docker-compose.prod.yml build prod
after_success: after_success:
- docker login -u=$DOCKER_USERNAME -p=$DOCKER_PASSWORD - docker login -u=$DOCKER_USERNAME -p=$DOCKER_PASSWORD
- docker push $DOCKER_IMAGE_DEV
- docker push $DOCKER_IMAGE_PROD - docker push $DOCKER_IMAGE_PROD
...@@ -9,8 +9,10 @@ ARG CI_REGISTRY_IMAGE ...@@ -9,8 +9,10 @@ ARG CI_REGISTRY_IMAGE
ARG CI_PROJECT_NAME ARG CI_PROJECT_NAME
ARG CI_BUILD_REF_NAME ARG CI_BUILD_REF_NAME
ARG CI_BUILD_TIME ARG CI_BUILD_TIME
ARG CI_BUILDER
ENV CI_BUILD_ID=$CI_BUILD_ID CI_BUILD_REF=$CI_BUILD_REF CI_REGISTRY_IMAGE=$CI_REGISTRY_IMAGE \ ENV CI_BUILD_ID=$CI_BUILD_ID CI_BUILD_REF=$CI_BUILD_REF CI_REGISTRY_IMAGE=$CI_REGISTRY_IMAGE \
CI_PROJECT_NAME=$CI_PROJECT_NAME CI_BUILD_REF_NAME=$CI_BUILD_REF_NAME CI_BUILD_TIME=$CI_BUILD_TIME CI_PROJECT_NAME=$CI_PROJECT_NAME CI_BUILD_REF_NAME=$CI_BUILD_REF_NAME \
CI_BUILD_TIME=$CI_BUILD_TIME CI_BUILDER=$CI_BUILDER
COPY dist /usr/share/nginx/html COPY dist /usr/share/nginx/html
FROM teracy/angular-cli:1.0.0-rc.2
LABEL authors="hoatle <hoatle@teracy.com>"
RUN mkdir -p /opt/app
ENV TERM=xterm APP=/opt/app
# add more arguments from CI to the image so that `$ env` should reveal more info
ARG CI_BUILD_ID
ARG CI_BUILD_REF
ARG CI_REGISTRY_IMAGE
ARG CI_PROJECT_NAME
ARG CI_BUILD_REF_NAME
ARG CI_BUILD_TIME
ENV CI_BUILD_ID=$CI_BUILD_ID CI_BUILD_REF=$CI_BUILD_REF CI_REGISTRY_IMAGE=$CI_REGISTRY_IMAGE \
CI_PROJECT_NAME=$CI_PROJECT_NAME CI_BUILD_REF_NAME=$CI_BUILD_REF_NAME CI_BUILD_TIME=$CI_BUILD_TIME \
npm_config_tmp=/tmp
ADD package.json yarn.lock $APP/
WORKDIR $APP
RUN yarn
VOLUME $APP/node_modules
# angular-hello-world [![Build Status](https://travis-ci.org/acme101/angular-hello-world.svg?branch=develop)](https://travis-ci.org/acme101/angular-hello-world) # angular-hello-world [![Build Status](https://travis-ci.org/acme101/angular-hello-world.svg?branch=develop)](https://travis-ci.org/acme101/angular-hello-world) [![build status](https://gitlab.com/acme101/angular-hello-world/badges/develop/build.svg)](https://gitlab.com/acme101/angular-hello-world/commits/develop)
This project was created from [angular-boilerplate](https://github.com/acme101/angular-boilerplate) This project was created from [angular-boilerplate](https://github.com/acme101/angular-boilerplate)
version 0.2.0. version 0.2.0.
# Getting started ## Getting started
Follow: https://github.com/acme101/dev-setup/blob/master/README.md Follow: https://github.com/acme101/dev-setup/blob/master/README.md
......
...@@ -12,6 +12,7 @@ services: ...@@ -12,6 +12,7 @@ services:
- CI_BUILD_REF_NAME=${CI_BUILD_REF_NAME} - CI_BUILD_REF_NAME=${CI_BUILD_REF_NAME}
- CI_BUILD_TIME=${CI_BUILD_TIME} - CI_BUILD_TIME=${CI_BUILD_TIME}
- CI_REGISTRY_IMAGE=${CI_REGISTRY_IMAGE} - CI_REGISTRY_IMAGE=${CI_REGISTRY_IMAGE}
- CI_BUILDER=${CI_BUILDER}
- CI_PROJECT_NAME=${CI_PROJECT_NAME} - CI_PROJECT_NAME=${CI_PROJECT_NAME}
image: ${DOCKER_IMAGE_PROD:-acme101/angular-hello-world:develop} image: ${DOCKER_IMAGE_PROD:-acme101/angular-hello-world:develop}
environment: environment:
......
...@@ -4,19 +4,9 @@ services: ...@@ -4,19 +4,9 @@ services:
dev: dev:
container_name: angular-hello-world_dev container_name: angular-hello-world_dev
build: image: ${DOCKER_IMAGE_DEV:-teracy/angular-cli:1.0.0-rc.2}
context: . working_dir: /opt/app
dockerfile: Dockerfile-dev command: sh run-dev.sh
args:
- CI_BUILD_ID=${CI_BUILD_ID}
- CI_BUILD_REF=${CI_BUILD_REF}
- CI_BUILD_REF_NAME=${CI_BUILD_REF_NAME}
- CI_BUILD_TIME=${CI_BUILD_TIME}
- CI_REGISTRY_IMAGE=${CI_REGISTRY_IMAGE}
- CI_PROJECT_NAME=${CI_PROJECT_NAME}
# we use image for faster developing with `npm install` already run
image: ${DOCKER_IMAGE_DEV:-acme101/angular-hello-world:dev_develop}
command: bash -c "yarn run start"
environment: environment:
NODE_ENV: development NODE_ENV: development
VIRTUAL_HOST: dev.ahw.acme.dev VIRTUAL_HOST: dev.ahw.acme.dev
...@@ -26,6 +16,6 @@ services: ...@@ -26,6 +16,6 @@ services:
ports: ports:
- "4200" - "4200"
restart: unless-stopped restart: unless-stopped
# to get this work with https://github.com/jwilder/nginx-proxy # to get this work with https://github.com/jwildder/nginx-proxy
# related: https://github.com/jwilder/nginx-proxy/issues/305 # related: https://github.com/jwilder/nginx-proxy/issues/305
network_mode: bridge network_mode: bridge
#!/bin/bash
set -e
yarn
yarn run start
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment