How to deploy to AWS using NUXTJS official S3 and CloudFront? With docker-compose

Introduction

How to deploy to AWS using S3 and CloudFront in the official documentation? I would like to summarize how to easily deploy with docker-compose.

(Official documentation) How to deploy to AWS using S3 and CloudFront?

Please refer to here for AWS (S3, CloudFront) settings.

1. File structure

nuxtapp/docker-compose.yml
nuxtapp/Dockerfile
nuxtapp/deploy.sh
nuxtapp/gulpfile.js

2. File preparation required for Docker conversion

Dockerfile


FROM node:12.18.3-alpine3.9
RUN apk add --no-cache openssh bash python make
RUN npm install -g gulp
RUN npm install --save-dev gulp gulp-awspublish gulp-cloudfront-invalidate-aws-publish concurrent-transform

docker-compose.yml


version: '3'

services:
  node: &app_base
    build: .
    # tty: true
    working_dir: /var/www
    volumes:
      - .:/var/www
    environment:
      PORT: 3000
      HOST: 0.0.0.0
  install:
    <<: *app_base
    command: npm ci
  dev:
    <<: *app_base
    ports:
      - "3000:3000"
    command: npm run dev
  generate:
    <<: *app_base
    command: npm run generate
  dev_static:
    image: httpd
    volumes:
      - ./dist:/usr/local/apache2/htdocs/
    ports:
      - "80:80"
  s3deploy:
    <<: *app_base
    command: ./deploy.sh

For docker-compose.yml, change the article here from yarn to npm, and use the Dockerfile to manually install the procedure in the container. I prepared it.

3. How to use

Each container should be defined in docker-compose.yml as needed.

Launch the application development environment

$ docker-compose up dev

Run npm run dev inside the container.

Static file generation

$ docker-compose up generate

Run npm run generate inside the container. The output result is output to nuxtapp / dist by default.

Local operation check of the output static file

$ docker-compose up dev_static

Expose the dist locally in the tomcat container. http://localhostにアクセスするとアプリを確認できます。

Deploy

$ docker-compose up s3deploy

Run deploy.sh inside the container.

If you follow the success image of the official procedure, you are done.

Recommended Posts

How to deploy to AWS using NUXTJS official S3 and CloudFront? With docker-compose
[Rails] How to upload images to AWS S3 using Carrierwave and fog-aws
[Rails] How to upload images to AWS S3 using refile and refile-s3
How to deploy Java to AWS Lambda with Serverless Framework
[Part 1] How to deploy Docker containers and static files with CircleCI + ECS + ECR + CloudFront
How to use MinIO with the same function as S3 Use docker-compose
How to monitor nginx with docker-compose with datadog
How to write and explain Dockerfile, docker-compose
How to realize hybrid search using morphological analysis and Ngram with Solr
How to use args :, environment :, env_file: and .env files with docker-compose command
Getting Started with Micronaut 2.x ~ Native Build and Deploy to AWS Lambda ~
How to output Excel and PDF using Excella
How to execute and mock methods using JUnit
How to deploy a container on AWS Lambda
How to play audio and music using javascript
[AWS] How to automatically deploy a Web application created with Rails 6 to ECR / ECS using CircleCI ① Preparation [Container deployment]
How to use Java framework with AWS Lambda! ??
How to save images on Heroku to S3 on AWS
How to deploy
How to send custom metrics and events to datadog with laravel in docker-compose environment
Deploy Rails to ECS Fargate with AWS Copilot
How to build API with GraphQL and Rails
[Docker] How to update using a container on Heroku and how to deal with Migrate Error
How to unit test with JVM with source using RxAndroid
I started MySQL 5.7 with docker-compose and tried to connect
How to serialize and deserialize LocalDateTime type with GSON
How to convert A to a and a to A using AND and OR in Java
How to download images from AWS S3 (rails, carrierwave)
How to use RealSense with ubuntu 20.04 and ROS Noetic
How to check CircleCI code and automatically deploy to Heroku
[Rails] Create sitemap using sitemap_generator and deploy to GAE
How to install Gradle and Kotlin with SDKMAN (Mac)
Common problems with WSL and how to deal with them
How to write docker-compose
How to create docker-compose
How to test including images when using ActiveStorage and Faker
How to set environment variables when using Payjp with Rails
How to transform ARKit and SceneKit shapes with Metal shader
How to set and describe environment variables using Rails zsh
How to deploy jQuery in your Rails app using Webpacker
How to deploy a kotlin (java) app on AWS fargate
How to make an app using Tensorflow with Android Studio
How to join a table without using DBFlute and sql
How to get started with JDBC using PostgresSQL on MacOS
How to deploy a Rails application on AWS (article summary)
How to register as a customer with Square using Tomcat
How to deal with different versions of rbenv and Ruby
Upload / download / bulk delete data to S3 using Amazon S3 Client Builder with AWS SDK for Java
How to use the certificate and private key created by Docker's BASIC authentication with AWS ALB
[AWS] How to check logs
How to deploy on heroku
How to number (number) with html.erb
How to update with activerecord-import
How to authorize using graphql-ruby
[Docker-compose] How to use unnamed and named volumes of volumes. Bind mount
Encrypt data uploaded to S3 using AWS SDK for Java / SSE-KMS
How to POST JSON in Java-Method using OkHttp3 and method using HttpUrlConnection-
[Rails] How to introduce kaminari with Slim and change the design
[Tips] How to solve problems with XCode and Swift for beginners
How to publish an application using AWS (3) EC2 instance environment construction
How to run a job with docker login in AWS batch