Skip to content

Commit

Permalink
Merge pull request #1 from nose221834/feat/nose/1628-ci
Browse files Browse the repository at this point in the history
Feat/nose/1628 ci
  • Loading branch information
nose221834 authored Oct 23, 2024
2 parents 4bc695c + 84443ec commit 1d5f78d
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
53 changes: 53 additions & 0 deletions .github/workflows/image-push-stage.yml
Original file line number Diff line number Diff line change
@@ -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: nutfes/group-manager-2-admin-view

- dockerfile: front.k8s.Dockerfile
image_name: nutfes/group-manager-2-user-front

- dockerfile: api.k8s.Dockerfile
image_name: nutfes/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: |
API_URL=https://group-manager-api.nosse.net
APP_API_URL=https://group-manager-api.nosse.net
CLIENT_ID=${{ secrets.NUXT_IMGUR_CLIENT_ID }}
CLIENT_SECRET=${{ secrets.NUXT_IMGUR_CLIENT_SECRET }}
50 changes: 50 additions & 0 deletions .github/workflows/image-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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: nutfes/group-manager-2-admin-view
- dockerfile: front.k8s.Dockerfile
image_name: nutfes/group-manager-2-user-front
- dockerfile: api.k8s.Dockerfile
image_name: nutfes/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 }}
45 changes: 45 additions & 0 deletions admin.k8s.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
8 changes: 8 additions & 0 deletions api.k8s.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions front.k8s.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 1d5f78d

Please sign in to comment.