LoginSignup
1
1

next build後は環境変数が変更できなくなる

Last updated at Posted at 2023-10-17

TL;DR

next build を行うとそれ以降環境変数が変更できなくなり、ECSのタスク定義で設定しても反映されない。

Before

FROM node:18-alpine
WORKDIR /usr/app
COPY ./src /usr/app/
COPY ./package.json /usr/app/
COPY ./yarn.lock /usr/app/
RUN yarn install && next build
EXPOSE 80

CMD ["next", "start"]

After

FROM node:18-alpine
WORKDIR /usr/app
COPY ./src /usr/app/
COPY ./package.json /usr/app/
COPY ./yarn.lock /usr/app/
COPY init.sh /usr/app/

RUN yarn install
EXPOSE 80
# init.shでは「next build」と「next start」が実行される 
CMD ["sh", "init.sh"] 

DockerのRUNはイメージ作成時に実行されます。
DockerのCMDはイメージを起動する時に実行されます。
ECSのタスク定義に設定された環境変数を適用するには、CMDnext buildを実行する必要がありました。

(以下記事を参考にしました🙇)

参考にした情報

以下のドキュメントから「ビルド後環境変数が変更できなくなる」ことがわかりました。

After being built, your app will no longer respond to changes to these environment variables. For instance, if you use a Heroku pipeline to promote slugs built in one environment to another environment, or if you build and deploy a single Docker image to multiple environments, all NEXT_PUBLIC_ variables will be frozen with the value evaluated at build time, so these values need to be set appropriately when the project is built.

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1