Skip to content

Instantly share code, notes, and snippets.

@kpavlovsky
Last active May 22, 2018 21:02
Show Gist options
  • Save kpavlovsky/d9529884510bd91d63de38fab44c8ede to your computer and use it in GitHub Desktop.
Save kpavlovsky/d9529884510bd91d63de38fab44c8ede to your computer and use it in GitHub Desktop.
Gitlab CI/CD Runner Scripts with Dockerfile to build Nodejs Angular 5 app in Docker
#!/usr/bin/env bash
if [ -z "${STAGE_PRIVATE_KEY}" ]; then echo "STAGE_PRIVATE_KEY is not set"; exit 255; fi
if [ -z "${STAGE_PUBLIC_KEY}" ]; then echo "STAGE_PRIVATE_KEY is not set"; exit 255; fi
pwd
ls
id
mkdir ~/.ssh/
echo -n "$STAGE_PRIVATE_KEY" > ~/.ssh/id_rsa
echo -n "$STAGE_PUBLIC_KEY" > ~/.ssh/id_rsa.pub
echo "Key permissions"
chmod 0700 ~/.ssh
chmod 0600 ~/.ssh/*
echo "Adding to known hosts"
ssh-keyscan -9999 SERVER >> ~/.ssh/known_hosts
echo "cat ~/.ssh/known_hosts:"
cat ~/.ssh/known_hosts
echo "switching to interface dir"
cd interface
echo "Moving node_modules from $HOME to interface directory"
mv /home/node/node_modules ./
echo "npm i"
npm i
echo "rm -rf -dist"
rm -rf dist
echo "ng build -e ru_prod --prod"
ng build -e ru_prod --prod
echo "scp -P 9999 -r dist/* user@SERVER:/sites/sitename/web_ru"
scp -P 9999 -r dist/* user@SERVER:/sites/sitename/web_ru
FROM node:9
USER node
RUN mkdir /home/node/.npm-global
ENV PATH=/home/node/.npm-global/bin:$PATH
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
COPY interface/package.json /home/node/
COPY interface/package-lock.json /home/node/
RUN npm i -g [email protected]
RUN npm i -g @angular/[email protected]
WORKDIR /home/node
RUN npm i
CMD [ "node" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment