Skip to content

Instantly share code, notes, and snippets.

@h1ddengames
Created February 28, 2021 07:38
Show Gist options
  • Save h1ddengames/b2488f27f2e3d5cc1518000b7ef1351a to your computer and use it in GitHub Desktop.
Save h1ddengames/b2488f27f2e3d5cc1518000b7ef1351a to your computer and use it in GitHub Desktop.
Vue Project Documentation

Vue Project Documentation

[One-Time] Required Dependencies

[One-Time] Creating a project using Vue CLI

  1. Open a terminal.
  2. Type the following:
    vue create vuetifyjs-template-project
    
  3. Select the "Manually select features" option.
  4. Choose Vue 2.X, Babel, Router, Linter, Unit Testing, and E2E Testing.
  5. Select "Yes" for "Use history mode for router?"
  6. Select "ESLint + Prettier" for "Pick a linter/ formatter config"
  7. Select "Lint on save" for "Pick additional lint features"
  8. Select "Mocha + Chai" for "Pick a unit testing solution"
  9. Select "WebdriverIO" for "Pick an E2E testing solution"
  10. Select "Chrome" and "Firefox" for "Pick browsers to run end-to-end test on"
  11. Select "In dedicated config files" for "Where do you prefer placing config for ..."
  12. Pick "Use NPM" for "Pick the package manager to use when installing dependencies"

[One-Time] Setup Vue project to run in Docker/Docker-Compose environment

  1. Create a file named Dockerfile in the root directory of the Vue project.

    FROM node:lts-alpine
    
    # Create app directory
    WORKDIR /app
    
    # A wildcard is used to ensure both package.json AND package-lock.json are copied
    # where available (npm@5+)
    COPY package*.json ./
    
    # Install app dependencies
    RUN npm install
    
    # If you are building your code for production
    # RUN npm ci --only=production
    
    # Bundle app source
    COPY . .
    
    EXPOSE 8080
    CMD ["npm", "run", "serve"]
    
  2. Create a file named docker-compose.yml in the root directory of the Vue project.

    version: '3.9'
    
    # Usage:
    ## Start up all services:
        ### docker-compose -f docker/docker-compose.yml up -d
        ## -f flag to specify the filename if filename is not docker-compose.yml or if it's not located in the current directory.
        ## -d flag is used to detach the container's output from the terminal so you can keep using the same terminal.
    ## Shutdown all services:
        ### docker-compose -f docker/docker-compose.yml down
        ## -f flag to specify the filename if filename is not docker-compose.yml or if it's not located in the current directory.
    services:
    # BACKUP MYSQL by generating dump file
        # docker exec CONTAINER-NAME mysqldump -u root --password=root DATABASE-NAME > backup.sql
    # RESTORE MYSQL from dump file
        # docker exec -i CONTAINER-NAME mysql -u root --password=root DATABASE-NAME < backup.sql
    db-node:
        container_name: db-node
        image: mysql:5.7
        restart: always
        command: --default-authentication-plugin=mysql_native_password
        env_file:
            - database.env
        ports:
        - target: 3306
            published: 3306
            protocol: tcp
            mode: host
    
    phpmyadmin-node:
        depends_on:
        - db-node
        container_name: phpmyadmin-node
        image: phpmyadmin/phpmyadmin:5.0.0
        restart: always
        env_file:
         - database.env
         - phpmyadmin.env
        ports:
        - target: 80
            published: 8081
            protocol: tcp
            mode: host
    
    app-node:
        depends_on:
        - db-node
        container_name: app-node
        build:
        context: .
        dockerfile: Dockerfile
        image: h1ddengames/vue-bootstrap-docker-node:1.0.0
        restart: always
        volumes:
        - ./:/app
        - /app/node_modules/
        ports:
        - target: 8080
            published: 8080
            protocol: tcp
            mode: host
    
  3. Fix the formatting in Dockerfile and docker-compose.yml

  4. Create two files named database.env and phpmyadmin.env

  5. Add the following to database.env

    MYSQL_ROOT_PASSWORD=YourPasswordHere
    MYSQL_USER=YourNonRootDatabaseUsernameHere
    MYSQL_PASSWORD=YourNonrootDatabaseUsersPasswordHere
    MYSQL_DATABASE=NameOfYourInitialDatabaseHere

    Example:

    MYSQL_ROOT_PASSWORD=password
    MYSQL_USER=db
    MYSQL_PASSWORD=password
    MYSQL_DATABASE=products
  6. Add the following to phpmyadmin.env

    PMA_HOST=db-node
    PMA_PORT=3306
    
  7. Create two files named database-example.env and phpmyadmin.env then add the following:

    For database-example.env

    # 0. DO NOT DIRECTLY MODIFY THIS FILE (database-example.env)
    # 1. Create a copy of this file called database.env
    # 2. Update each environment field below these lines.
    # 3. Remove these comments (lines starting with '#')
    MYSQL_ROOT_PASSWORD=
    MYSQL_USER=
    MYSQL_PASSWORD=
    MYSQL_DATABASE=

    For phpmyadmin-example.env

    # 0. DO NOT DIRECTLY MODIFY THIS FILE (phpmyadmin-example.env)
    # 1. Create a copy of this file called phpmyadmin.env
    # 2. Update each environment field below these lines.
    # 3. Remove these comments (lines starting with '#')
    PMA_HOST=
    PMA_PORT=
  8. Add database.env and phpmyadmin.env to .gitignore

    .DS_Store
    node_modules
    /dist
    
    
    /tests/e2e/logs/
    
    # local env files
    .env.local
    .env.*.local
    database.env
    phpmyadmin.env
    
    # Log files
    npm-debug.log*
    yarn-debug.log*
    yarn-error.log*
    pnpm-debug.log*
    
    # Editor directories and files
    .idea
    .vscode
    *.suo
    *.ntvs*
    *.njsproj
    *.sln
    *.sw?
    

[Every time] Development in Docker container

  1. Before starting development on this Vue application make sure that the Docker image created in the previous step Setup Vue project to run in Docker/Docker-Compose environment is running as a container.
  2. If it is not running, open a terminal in the root directory of this project.
  3. Run the following command:
    docker-compose up -d
    
  4. Wait for the container to start, then visit the development server
  5. Once development is finished for the day, run the following command:
    docker-compose down
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment