Юрий Чихрай
Николай Романюк (Team lead в Blackthorn Vision) ©
ТЗ:
Docker - ПО с открытым исходным кодом, предназначенное для автоматизации развёртывания и управления приложениями в средах с поддержкой контейнеризации
Должен решать проблемы:
Главные сущности Docker
Dockerfile
FROM node:12-alpine
LABEL example_for="OdessaFrontend"
ENV NODE_ENV=DEV
ENV PORT=3001
# Create app directory
WORKDIR /usr/app
# Install app dependencies
COPY package*.json ./
RUN npm install
# Bundle app source
COPY ./dist .
EXPOSE 3001
CMD [ "node", "main.js" ]
# docker image build -t fake-server:v1 .
# docker run -p 3001:3001 fake-server:v1
docker-compose.yml
version: '3.7'
services:
redis:
container_name: redis
image: redis
ports:
- '127.0.0.1:6379:6379'
mongo:
container_name: mongodb
hostname: mongodb
restart: always
image: mongo
command:
- '-f'
- '/etc/mongod.conf'
ports:
- '127.0.0.1:27017:27017'
volumes:
- ~/mongo:/data/db
- ./mongod.conf:/etc/mongod.conf
node_app:
container_name: node_app
restart: always
image: fake-server:v1
environment:
PORT: 3001
NODE_ENV: DEV
ports:
- '127.0.0.1:3001:3001'
depends_on:
- mongo
- redis
# docker-compose up -d
BFG 9000*
Лучше, если этим занимается специальнообученный DevOps...
"scripts": {
"build": "npx gulp build",
"build-and-zip": "npm run build && rm -f client.zip && zip -r client.zip dist/",
"dist:backup": "rm -rf ./dist_backup && cp -r ./dist ./dist_backup",
"dist:restore": "rm -rf ./dist && mv ./dist_backup ./dist",
"dist:update": "npm run dist:backup && git pull && npm run build"
},
image: node:lts-alpine
variables:
FILE_NAME: client_$CI_PIPELINE_IID.zip
stages:
- build
- deploy
build_job:
stage: build
only:
- tags
- /^build/
cache:
paths:
- node_modules/
key: "node_modules"
script:
- apk add --no-cache zip
- npm i
- npm run build-and-zip
- mv client.zip $FILE_NAME
artifacts:
expire_in: 60d
paths:
- $FILE_NAME
deploy_job:
image: alpine
stage: deploy
when: manual
only:
- tags
- /^build/
before_script:
- which ssh-agent || ( apk --update add openssh-client )
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_PRIVATE_KEY" | ssh-add - > ~/.ssh/id_rsa
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
dependencies:
- build_job
script:
- scp -P $SSH_PORT ./$FILE_NAME $USER@$HOST:/home/$USER/$FILE_NAME
- >
ssh -p $SSH_PORT $USER@$HOST "unzip -o ./$FILE_NAME -d /var/www/html_new && rm -rf ./$FILE_NAME
&& cd /var/www/ && rm -rf ./html_back && mv ./html ./html_back && mv ./html_new ./html"
variables:
GIT_STRATEGY: none
@yurii.chikhrai