Dockerfile 3.98 KB
Newer Older
nabil el mahiri committed
1
# Stage 0, "build-stage", based on Node.js, to build and compile Angular
nabil el mahiri committed
2
FROM node:6.11.1 as build-stage
nabil el mahiri committed
3

4 5 6 7 8
# Take an SSH key build token and deploy token as a build argument.
ARG SSH_PRIVATE_KEY
ARG BUILD_TOKEN
ARG DEPLOY_TOKEN

9 10
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get -y dist-upgrade
nabil el mahiri committed
11 12

# Installing supervisord
13
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y supervisor && \
14 15 16
apt-get install -y gnupg2 && \
apt-get install -yq ssh && \
apt-get install -y openssh-server && \
17 18 19
apt-get install -yq redis-server

# add supervisor conf
nabil el mahiri committed
20 21
ADD ./docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf 
 
22
# install nginx
23
RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install net-tools nginx lsb-release
nabil el mahiri committed
24

25 26 27
RUN rm -f /etc/nginx/fastcgi.conf /etc/nginx/fastcgi_params && \
    rm -f /etc/nginx/snippets/fastcgi-php.conf /etc/nginx/snippets/snakeoil.conf && \
    rm -f /etc/nginx/sites-available/default && \
nabil el mahiri committed
28 29
    rm -f /etc/nginx/sites-enabled/default

30
# copy nginx conf
nabil el mahiri committed
31 32 33
COPY /nginx/default.conf /etc/nginx/sites-available
COPY /nginx/default.conf /etc/nginx/sites-enabled

34
# install grunt
nabil el mahiri committed
35
RUN npm install --global grunt-cli 
nabil el mahiri committed
36

37
# install mongo version 3.4 
38 39 40 41
# 1. add mongo repo 
# 2. install mongo 
# 3. create db folder 
# 4. run mongo in background
42 43
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 && \ 
    echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 main" | tee /etc/apt/sources.list.d/mongodb-org-3.4.list
44 45 46 47
RUN apt-get update && apt-get -yq install mongodb-org  
RUN mkdir -p /data/db 
RUN mongod --fork --syslog

48
# install expect form automatic npm login
nabil el mahiri committed
49
RUN apt-get -yq install expect-dev
nabil el mahiri committed
50

51
# dump mongo db 
nabil el mahiri committed
52 53 54 55
# sudo ./mongodb/bin/mongodump --host localhost --port 27017 --db atlasvoyages-dev --out ./

# sudo ./mongodb/bin/mongodump --host localhost --port 27017 --db atlasvoyages-dev --gzip --archive=atlasvoyages-dev.archive

nabil el mahiri committed
56
# RUN git config --global http.proxy http://<username>:<password>@<proxy-server-url>:<port>
nabil el mahiri committed
57

58
# RUN echo "//<npm-registry>:8080/:_authToken=KB9DEBiM5vNeGPwinPuj" > ~/.npmrc
nabil el mahiri committed
59

60

nabil el mahiri committed
61
# RUN echo exit 0 > /usr/sbin/policy-rc.d
nabil el mahiri committed
62
 
nabil el mahiri committed
63 64 65 66
# 1. Create the SSH directory.
# 2. Populate the private key file.
# 3. Set the required permissions.
# 4. Add github to our list of known hosts for ssh.
67 68 69 70 71
RUN mkdir ~/.ssh && \
    echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_rsa && \ 
    chmod 0600 ~/.ssh/id_rsa && \
    echo "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config && \ 
    touch ~/.ssh/known_hosts && ssh-keyscan -t rsa labs.atlasvoyages.com >> ~/.ssh/known_hosts && \ 
nabil el mahiri committed
72
    ssh -T git@labs.atlasvoyages.com 
nabil el mahiri committed
73
    # echo "Host labs.atlasvoyages.com"$'\n\t'"IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config
nabil el mahiri committed
74
 
nabil el mahiri committed
75

76 77
RUN cat ~/.ssh/known_hosts 
RUN cat ~/.ssh/id_rsa
nabil el mahiri committed
78 79 80

WORKDIR /atlasvoyages

81
COPY ./sh /atlasvoyages/sh
nabil el mahiri committed
82

83
# RUN login automatiquely to npm
84
RUN expect -f ./sh/npm_login_expect nabilelmahiri arigatou@65 "nabil.elmahiri@fractalite.com" 
nabil el mahiri committed
85

nabil el mahiri committed
86
COPY package*.json /atlasvoyages/
nabil el mahiri committed
87

88

89
# RUN include deploy token in gitlab urls in each of the modules
90
# RUN sed -i 's/git+ssh:\/\/git@labs.atlasvoyages.com:/git+http:\/\/gitlab-ci-token:'$DEPLOY_TOKEN'@labs.atlasvoyages.com\//' ./package.json
nabil el mahiri committed
91

92
RUN npm install --unsafe-perm=true 
nabil el mahiri committed
93

nabil el mahiri committed
94
COPY ./ /atlasvoyages/
nabil el mahiri committed
95

nabil el mahiri committed
96 97
WORKDIR /atlasvoyages/node_modules

98
# restore mongo db database
nabil el mahiri committed
99
# RUN mongorestore --host localhost --port 27017 --gzip --archive=atlasvoyages-dev.archive
nabil el mahiri committed
100

nabil el mahiri committed
101 102 103
RUN find . -maxdepth 1 -name "pine*" -type d \( ! -name . \) -exec bash -c "cd '{}' && npm i --unsafe-perm=true && grunt build:dist" \; && \
    find . -maxdepth 1 -name "hermes*" -type d \( ! -name . \) -exec bash -c "cd '{}' && npm i --unsafe-perm=true && grunt build:dist" \; && \
    find . -maxdepth 1 -name "theme-atlasvoyages*" -type d \( ! -name . \) -exec bash -c "cd '{}' && npm i --unsafe-perm=true && grunt build:dist" \;
nabil el mahiri committed
104 105

WORKDIR /atlasvoyages
nabil el mahiri committed
106 107 108 109 110 111 112 113 114

RUN echo '\n' | grunt pine:setup

RUN grunt pine:copy

# expose port 80 443
EXPOSE 80
EXPOSE 443

115
# setup endpoint for the final container
nabil el mahiri committed
116 117
ENTRYPOINT ["/usr/bin/supervisord"]