简体   繁体   中英

Gitlab Runner and docker/docker-compose passing stored gitlab variables

I have stored variables in My Gitlab project I would like to pass this variables so when i build the nuxtjs app all the vars should be available like Google API keys Firebase credentials

在此处输入图像描述

These are my files:

Dockerfile

FROM node:12.13.0-alpine

RUN mkdir -p /usr/src/project-name
WORKDIR /usr/src/project-name

RUN apk update && apk upgrade
RUN apk add git

COPY . /usr/src/project-name/
RUN npm install
RUN npm run build

EXPOSE 3000

ENV NUXT_HOST=0.0.0.0
ENV PORT=3000

CMD [ "npm", "start" ]

Docker-compose

version: "3.8"

services:
  nuxt:
    build: .
    ports:
      - "3000:3000"

.gitlab-ci.yml

stages:
  - deploy

deployFrontend:
  stage: deploy
  only:
    - deploy
  tags:
    - deploy
  script:
    - sudo docker-compose -f docker-compose.yml build --no-cache
    - sudo docker-compose -f docker-compose.yml up -d
  when: manual

You should pass Vars to the Docker build in.gitlab-ci.yml and catch them in Dockerfile:

(for example I take two Vars of your list)

Dockerfile


FROM node:12.13.0-alpine

ARG FIREBASE_API_KEY
ENV FIREBASE_API_KEY=$FIREBASE_API_KEY
ARG FIREBASE_API_ID
ENV FIREBASE_API_ID=$FIREBASE_API_ID
...
...
CMD [ "npm", "start" ]

.gitlab-ci.yml


- sudo export FIREBASE_API_KEY=$FIREBASE_API_KEY
- sudo export FIREBASE_API_ID=$FIREBASE_API_ID

- sudo docker build --build-arg FIREBASE_API_KEY --build-arg FIREBASE_API_ID -t NAME_OF_IMAGE -f path_to_Dockerfile .

- sudo docker-compose -f docker-compose.yml up -d
# in docker-compose.yml use NAME_OF_IMAGE you built above

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM