Skip to content

Commit

Permalink
環境変数をbuild時に渡す
Browse files Browse the repository at this point in the history
  • Loading branch information
nose221834 committed Jun 18, 2024
1 parent 3e2a83b commit 394ec1c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/image-push-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,24 @@ jobs:
include:
- dockerfile: admin.k8s.Dockerfile
image_name: nutfes/group-manager-2-admin-view
vue_app_url: ''
vue_app_api_url: ''
imgur_id: ''
imgur_token: ''

- dockerfile: front.k8s.Dockerfile
image_name: nutfes/group-manager-2-user-front
vue_app_url: ${{ secrets.VUE_APP_URL }}
vue_app_api_url: ${{ secrets.VUE_APP_API_URL }}
imgur_id: ${{ secrets.NUXT_IMGUR_CLIENT_ID }}
imgur_token: ${{ secrets.NUXT_IMGUR_CLIENT_SECRET }}

- dockerfile: api.k8s.Dockerfile
image_name: nutfes/group-manager-2-api
vue_app_url: ${{ secrets.VUE_APP_URL }}
vue_app_api_url: ${{ secrets.VUE_APP_API_URL }}
imgur_id: ''
imgur_token: ''


steps:
Expand All @@ -43,4 +57,9 @@ jobs:
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ matrix.image_name }}:latest
build-args: |
VUE_APP_URL=${{ matrix.vue_app_url }}
VUE_APP_API_URL=${{ matrix.vue_app_api_url }}
NUXT_IMGUR_CLIENT_ID=${{ matrix.imgur_id }}
NUXT_IMGUR_CLIENT_SECRET=${{ matrix.imgur_token }}
8 changes: 8 additions & 0 deletions admin.k8s.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
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 ./

Expand Down
16 changes: 12 additions & 4 deletions front.k8s.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@
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

Expand All @@ -18,11 +28,9 @@ 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

Expand Down

0 comments on commit 394ec1c

Please sign in to comment.