From 470cef967797fa3455c2c583c59a2f858966e853 Mon Sep 17 00:00:00 2001 From: Harsha Srikara Date: Mon, 8 Mar 2021 22:34:11 -0600 Subject: [PATCH] containerize application + new dev/prod envs + new CI workflow --- .dockerignore | 6 +++++ .github/workflows/docker-publish.yml | 33 ++++++++++++++++++++++++++++ .nginx/nginx.conf | 15 +++++++++++++ Dockerfile | 32 +++++++++++++++++++++++++++ Dockerfile.dev | 11 ++++++++++ docker-compose.dev.yml | 12 ++++++++++ docker-compose.yml | 7 ++++++ start.sh | 3 +++ 8 files changed, 119 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker-publish.yml create mode 100644 .nginx/nginx.conf create mode 100644 Dockerfile create mode 100644 Dockerfile.dev create mode 100644 docker-compose.dev.yml create mode 100644 docker-compose.yml create mode 100755 start.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..02a40af --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.github +.idea +build/ +node_modules/ +/node_modules +.DS_Store \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..23eec16 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,33 @@ +name: Publish Docker image +on: + release: + types: [published] + push: + branches: + - master + - dev + pull_request: + branches: [dev] + +jobs: + push_to_registries: + name: Push Docker Image to DockerHub and Github Packages + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v2 + - name: Push to Docker Hub + uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: acmutd/portal + tag_with_ref: true + - name: Push to GitHub Packages + uses: docker/build-push-action@v1 + with: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: docker.pkg.github.com + repository: acmutd/portal/portal + tag_with_ref: true \ No newline at end of file diff --git a/.nginx/nginx.conf b/.nginx/nginx.conf new file mode 100644 index 0000000..4816f0d --- /dev/null +++ b/.nginx/nginx.conf @@ -0,0 +1,15 @@ +worker_processes 4; + +events { worker_connections 1024; } + +http { + server { + listen 3000; + root /usr/share/nginx/html; + include /etc/nginx/mime.types; + + location /appui { + try_files $uri /index.html; + } + } +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c4931be --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# stage1 as builder +FROM node:alpine as builder + +# copy the package.json to install dependencies +COPY package.json package-lock.json ./ + +# Install the dependencies and make the folder +RUN npm install && mkdir /react-ui && mv ./node_modules ./react-ui + +WORKDIR /react-ui + +COPY . . + +# Build the project and copy the files +RUN npm run build + + +FROM nginx:alpine + +#!/bin/sh + +COPY ./.nginx/nginx.conf /etc/nginx/nginx.conf + +## Remove default nginx index page +RUN rm -rf /usr/share/nginx/html/* + +# Copy from the stahg 1 +COPY --from=builder /react-ui/build /usr/share/nginx/html + +EXPOSE 3000 3000 + +ENTRYPOINT ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..64e197f --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,11 @@ +FROM node:alpine + +WORKDIR /app + +COPY package.json /app + +RUN npm install + +COPY . /app + +CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..7243c41 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,12 @@ +version: "3.8" +services: + client: + stdin_open: true + build: + context: . + dockerfile: Dockerfile.dev + ports: + - "3000:3000" + volumes: + - "/app/node_modules" + - "./:/app" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2d8c8cd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: "3.8" +services: + portal: + stdin_open: true + image: acmutd/portal:latest + ports: + - "3000:3000" \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..05362ee --- /dev/null +++ b/start.sh @@ -0,0 +1,3 @@ +#!bin/bash + +npm start