Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/nose/cicd test #1671

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5838354
PRを作成した際にビルドする
nose221834 May 19, 2024
4083bca
環境変数の設定
nose221834 May 19, 2024
90394cf
チェックアウトしてからenvを作成
nose221834 May 19, 2024
926a21b
k8sで使う用のマルチステージングビルドするDockerfile
nose221834 May 19, 2024
955c983
ユーザー画面のdockerFile作成
nose221834 Jun 2, 2024
8b4488b
k8s用のimageを作成するDockerileを作成
nose221834 Jun 2, 2024
10295d8
mergeされたらdocker hubにpushする
nose221834 Jun 2, 2024
29066c0
特定のファイルが変更された場合のみ実行
nose221834 Jun 2, 2024
91c349b
いづれstage環境のために利用
nose221834 Jun 2, 2024
a1c342c
ファイルの指定方法を修正
nose221834 Jun 2, 2024
7f2aac1
push先を変更
nose221834 Jun 2, 2024
3e2a83b
k8sでは_が利用できないため、-に修正
nose221834 Jun 8, 2024
394ec1c
環境変数をbuild時に渡す
nose221834 Jun 18, 2024
078b8df
条件の変更
nose221834 Jun 18, 2024
7b43aa0
ワークフローの修正
nose221834 Jun 18, 2024
53b48bc
ifを削除
nose221834 Jun 18, 2024
ce5fa81
matrix内でのsecretsの利用をやめる
nose221834 Jun 18, 2024
a504a33
本番用のワークフローを修正
nose221834 Jun 18, 2024
fca42fd
dockerfileに渡す環境変数を修正
nose221834 Jun 19, 2024
84443ec
自分の環境で試すために変更
nose221834 Jun 19, 2024
1d5f78d
Merge pull request #1 from nose221834/feat/nose/1628-ci
nose221834 Oct 23, 2024
3f18763
リポジトリ名を変更
nose221834 Oct 23, 2024
c5828b4
修正
nose221834 Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 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 }}
47 changes: 47 additions & 0 deletions .github/workflows/image-push.yml
Original file line number Diff line number Diff line change
@@ -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 }}
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"]
Loading