diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 000000000..7315e6057 --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,53 @@ +name: Docker Build and Test + +on: + pull_request: + paths: + - 'admin_view/**' + - 'user_front/**' + - 'api/**' + + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Create envfile + uses: SpicyPizza/create-envfile@v2.0 + with: + BOT_USER_ACCESS_TOKEN: ${{ secrets.BOT_USER_ACCESS_TOKEN }} + CHANNEL: ${{ secrets.CHANNEL }} + NUTMEG_MYSQL_DBNAME: ${{ secrets.NUTMEG_MYSQL_DBNAME }} + NUTMEG_MYSQL_HOST: ${{ secrets.NUTMEG_MYSQL_HOST }} + NUTMEG_MYSQL_PASSWORD: ${{ secrets.NUTMEG_MYSQL_PASSWORD }} + NUTMEG_MYSQL_USERNAME: ${{ secrets.NUTMEG_MYSQL_USERNAME }} + RAILS_ENV: ${{ secrets.RAILS_ENV }} + RAILS_LOG_TO_STDOUT: ${{ secrets.RAILS_LOG_TO_STDOUT }} + RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} + VUE_APP_API_URL: ${{ secrets.VUE_APP_API_URL }} + VUE_APP_URL: ${{ secrets.VUE_APP_URL }} + WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} + file_name: group-manager-2.env + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build Docker image + run: docker compose -f docker-compose.prod.yml build + + - name: install admin_view + run: docker compose -f docker-compose.prod.yml run --rm admin_view npm i + + - name: install user_front + run: docker compose -f docker-compose.prod.yml run --rm user_front npm i + + - name: Build admin_view + run: docker compose -f docker-compose.prod.yml run --rm admin_view npm run build + + - name: Build user_front + run: docker compose -f docker-compose.prod.yml run --rm user_front npm run build diff --git a/.github/workflows/image-push-stage.yml b/.github/workflows/image-push-stage.yml new file mode 100644 index 000000000..7d45efe08 --- /dev/null +++ b/.github/workflows/image-push-stage.yml @@ -0,0 +1,53 @@ +name: Build and Push Multiple Docker Images + +on: + pull_request: + types: [opened, synchronize, reopened, closed] + +jobs: + build-and-push: + runs-on: ubuntu-latest + if: | + github.event.pull_request.merged == true || + github.event.action == 'opened' || + github.event.action == 'synchronize' || + github.event.action == 'reopened' + strategy: + matrix: + include: + - dockerfile: admin.k8s.Dockerfile + image_name: nose0118/group-manager-2-admin-view + + - dockerfile: front.k8s.Dockerfile + image_name: nose0118/group-manager-2-user-front + + - dockerfile: api.k8s.Dockerfile + image_name: nose0118/group-manager-2-api + + steps: + - uses: actions/checkout@v4 + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Log in to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + file: ${{ matrix.dockerfile }} + push: true + tags: ${{ matrix.image_name }}:latest + build-args: | + VUE_APP_URL=${{ secrets.VUE_APP_URL }} + VUE_APP_API_URL=${{ secrets.VUE_APP_API_URL }} + NUXT_IMGUR_CLIENT_ID=${{ secrets.NUXT_IMGUR_CLIENT_ID }} + NUXT_IMGUR_CLIENT_SECRET=${{ secrets.NUXT_IMGUR_CLIENT_SECRET }} diff --git a/.github/workflows/image-push.yml b/.github/workflows/image-push.yml new file mode 100644 index 000000000..e7d9380b9 --- /dev/null +++ b/.github/workflows/image-push.yml @@ -0,0 +1,47 @@ +name: Build and Push Multiple Docker Images + +on: + pull_request: + types: [closed] + +jobs: + build-and-push: + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true + strategy: + matrix: + include: + - dockerfile: admin.k8s.Dockerfile + image_name: nose0118/group-manager-2-admin-view + - dockerfile: front.k8s.Dockerfile + image_name: nose0118/group-manager-2-user-front + - dockerfile: api.k8s.Dockerfile + image_name: nose0118/group-manager-2-api + + steps: + - uses: actions/checkout@v4 + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Log in to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + file: ${{ matrix.dockerfile }} + push: true + tags: ${{ matrix.image_name }}:latest + build-args: | + VUE_APP_URL=${{ secrets.VUE_APP_URL }} + VUE_APP_API_URL=${{ secrets.VUE_APP_API_URL }} + NUXT_IMGUR_CLIENT_ID=${{ secrets.NUXT_IMGUR_CLIENT_ID }} + NUXT_IMGUR_CLIENT_SECRET=${{ secrets.NUXT_IMGUR_CLIENT_SECRET }} diff --git a/admin.k8s.Dockerfile b/admin.k8s.Dockerfile new file mode 100644 index 000000000..10bdd9f06 --- /dev/null +++ b/admin.k8s.Dockerfile @@ -0,0 +1,45 @@ +# Stage 1: Install dependencies and build the project +FROM node:16-bookworm-slim AS builder +WORKDIR /app + +# Accept API URL as a build-time environment variable +ARG API_URL +ARG APP_API_URL + +# Set the environment variable +ENV VUE_APP_URL=${API_URL} +ENV VUE_APP_API_URL=${APP_API_URL} + +# Copy package.json and package-lock.json (or npm-shrinkwrap.json) +COPY ./admin_view/nuxt-project/package*.json ./ + +# Install dependencies +RUN npm ci + +# Copy Nuxt.js application source code +COPY ./admin_view/nuxt-project/ ./ + +# Build the application +RUN npm run build + +# Stage 2: Serve the app using a Node.js server +FROM node:16-bookworm-slim AS runner +WORKDIR /app + +# Copy the built server and client code +COPY --from=builder /app/nuxt.config.js ./nuxt.config.js +COPY --from=builder --chown=nonroot:nonroot /app/.nuxt ./.nuxt +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/package.json ./package.json +COPY --from=builder /app/package-lock.json ./package-lock.json +COPY --from=builder /app/store ./store +COPY --from=builder /app/static ./static +COPY --from=builder /app/assets ./assets +# Set environment variables +ENV NODE_ENV production + +# Expose the port the app runs on +EXPOSE 8000 + +# Start the application +CMD ["node_modules/.bin/nuxt", "start"] diff --git a/api.k8s.Dockerfile b/api.k8s.Dockerfile new file mode 100644 index 000000000..54068c179 --- /dev/null +++ b/api.k8s.Dockerfile @@ -0,0 +1,8 @@ +FROM ruby:2.7.1 +WORKDIR /myapp +ENV RAILS_ENV="production" +ENV RAILS_LOG_TO_STDOUT=ON +COPY ./api /myapp +RUN bundle install +CMD ["rails", "server", "-b", "0.0.0.0", "-p", "3000"] +EXPOSE 3000 \ No newline at end of file diff --git a/front.k8s.Dockerfile b/front.k8s.Dockerfile new file mode 100644 index 000000000..810c730b8 --- /dev/null +++ b/front.k8s.Dockerfile @@ -0,0 +1,38 @@ +# Stage 1: Install dependencies and build the project +FROM node:18-bookworm-slim AS builder +WORKDIR /app + +# Accept API URL as a build-time environment variable +ARG API_URL +ARG APP_API_URL +ARG IMGUR_ID +ARG IMGUR_SECRET + +# Set the environment variable +ENV VUE_APP_URL=${API_URL} +ENV VUE_APP_API_URL=${APP_API_URL} +ENV NUXT_IMGUR_CLIENT_ID=${IMGUR_ID} +ENV NUXT_IMGUR_CLIENT_SECRET=${IMGUR_SECRET} + +# Install postinstall necessary for Nuxt 3 +COPY ./user_front/package*.json ./ +RUN npm ci +# Copy the rest of your Vue.js application source code +COPY ./user_front/ ./ +# Build the application +RUN npm run build + +# Stage 2: Serve the app using a Node.js server +FROM node:18-bookworm-slim AS runner +WORKDIR /app + +# Copy the built server and client code +COPY --from=builder /app/.output ./output +# Set environment variables +ENV NODE_ENV production + +# Expose the port the app runs on +EXPOSE 3000 + +# Start the application +CMD ["node", "output/server/index.mjs"]