Nuxtアプリケーションの本サーバ展開関連
API - Koa + TypeScript
Front - Nuxt SSR
サーバの初期化・保守管理が結構あった
サーバの初期設定・管理が結構大変
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update
apt-get install -y docker-ce
usermod -aG docker ubuntu
mkdir /app
mkdir /app/nginx
cat <<EOL > /app/nginx/default.conf
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://app:3000;
proxy_set_header Host \$host;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
EOL
cat <<EOL > /app/docker-compose.yml
version: '3.1'
services:
app:
image: wakachan/nuxt-sample-project:release
working_dir: /home/node/app
deploy:
replicas: 2
nginx:
image: nginx:1.15
ports:
- "80:80"
volumes:
- ./nginx:/etc/nginx/conf.d
depends_on:
- app
EOL
docker swarm init
docker stack deploy -c /app/docker-compose.yml sample
build:
docker:
- image: circleci/python:3.6.1
environment:
AWS_DEFAULT_OUTPUT: json
steps:
- setup_remote_docker
- run:
name: Install awscli
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
- save_cache:
key: v1-{{ checksum "requirements.txt" }}
paths:
- "venv"
- run:
name: docker build
command: rm -rf app/node_modules && docker build --no-cache -t app:release -f Dockerfile.
- run:
name: add tag to docker
command: docker tag apprelease 387567903544.dkr.ecr.ap-northeast-1.amazonaws.com/wakai/app:release
- run:
name: Push image
command: |
. venv/bin/activate
eval $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
docker push 387567903544.dkr.ecr.ap-northeast-1.amazonaws.com/wakai/app:release
deploy:
machine: true
steps:
- add_ssh_keys:
fingerprints:
- "69:d9:3b:23:6d:65:f3:6d:8e:a7:f9:c0:2e:e1:4f:c4"
- run:
name: staging delpoy
command: >
ssh ubuntu@aaaaaa.com "sh deploy.sh"
#!/usr/bin/env bash
export PATH=/home/ubuntu/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
sudo $(aws ecr get-login --no-include-email --region ap-northeast-1)
sudo docker-compose pull sample
docker stack deploy -c docker-compose.yml --with-registry-auth project-tool
アプリケーションの開発に時間が取れなくなってきた
runtime: nodejs10
instance_class: F2
env_variables:
HOST: '0.0.0.0'
PORT: '8080'
SQL_USER: user
SQL_PASSWORD: password
SQL_DATABASE: user
INSTANCE_CONNECTION_NAME: app-9999:asia-northeast1:app
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update
apt-get install -y docker-ce
usermod -aG docker ubuntu
mkdir /app
mkdir /app/nginx
cat <<EOL > /app/nginx/default.conf
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://app:3000;
proxy_set_header Host \$host;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
EOL
cat <<EOL > /app/docker-compose.yml
version: '3.1'
services:
app:
image: wakachan/nuxt-sample-project:release
working_dir: /home/node/app
deploy:
replicas: 2
nginx:
image: nginx:1.15
ports:
- "80:80"
volumes:
- ./nginx:/etc/nginx/conf.d
depends_on:
- app
EOL
docker swarm init
docker stack deploy -c /app/docker-compose.yml sample
build:
docker:
- image: circleci/python:3.6.1
environment:
AWS_DEFAULT_OUTPUT: json
steps:
- setup_remote_docker
- run:
name: Install awscli
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
- save_cache:
key: v1-{{ checksum "requirements.txt" }}
paths:
- "venv"
- run:
name: docker build
command: rm -rf app/node_modules && docker build --no-cache -t app:release -f Dockerfile.
- run:
name: add tag to docker
command: docker tag apprelease 387567903544.dkr.ecr.ap-northeast-1.amazonaws.com/wakai/app:release
- run:
name: Push image
command: |
. venv/bin/activate
eval $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
docker push 387567903544.dkr.ecr.ap-northeast-1.amazonaws.com/wakai/app:release
deploy:
machine: true
steps:
- add_ssh_keys:
fingerprints:
- "69:d9:3b:23:6d:65:f3:6d:8e:a7:f9:c0:2e:e1:4f:c4"
- run:
name: staging delpoy
command: >
ssh ubuntu@aaaaaa.com "sh deploy.sh"
#!/usr/bin/env bash
export PATH=/home/ubuntu/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
sudo $(aws ecr get-login --no-include-email --region ap-northeast-1)
sudo docker-compose pull sample
docker stack deploy -c docker-compose.yml --with-registry-auth project-tool
いい感じにサーバレスになったので
アプリケーション開発に時間が増えた
しかも無料枠で動かせる
■静的サイトやSPAでNuxtを使用
↓
Netlify・Firebase Hosting
■SSRやAPIを自動デプロイでいい感じにNuxtを使用
↓
LightsailよりGAE