使用Gitlab CI部署Angular App会导致tmp目录中出现错误



晚上好,我正在尝试通过Gitlab CI将我的Angular应用程序部署到Heroku。我在Angular中的环境文件中保存了一个API密钥。我正在Gitlab CI中创建文件夹和文件,但我收到以下错误:

src/main.ts:5:29-错误TS2307:找不到模块"/environments/environment’或其相应的类型声明。5从"导入{environment}/环境/环境;

错误:";出现未处理的异常:文件替换中的/tmp/build_eef7fc3b/src/environment/enenvironment.prod.ts路径不存在。参见"/tmp/n-V6VwXu/角度误差.log";了解更多详细信息">

从Gitlab输出:"$ls-ld"$TP/"*-rw-r-r--。1根103 1月15日00:38/src/environment/environment.prod.ts-rw-r-r--。1根104 1月15日00:38/src/environments/environment.ts";

Gitlab似乎从我想要的目录转到了tmp文件夹。我不知道如何访问那个特定的文件夹,也不知道它为什么会更改。我在下面也有我的.yml文件。感谢您的时间和帮助。

# For the testing stage you must include all those lines so the tests run and finish. If  ng test doesnt have the flags that come after it, it will hang on that stage.
image: node:latest
before_script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
stages:
- production


production:
type: deploy
stage: production
image: ruby:latest
script:
- pwd
- (which ifconfig) || apt install net-tools
- ifconfig
- (which dig) || apt install dnsutils
- dig +short myip.opendns.com @resolver1.opendns.com
- TP=./src/environments
- TF="$TP/environment.ts"
- PE="$TP/environment.prod.ts"
- echo "$PE"
- mkdir -p "$TP"
- realpath "$PE"
- echo "$TF"
- printf "export const environment = { nt production:false,nt youtube:'%s' n};n" "$youtube" > "$TF"
- printf "export const environment = { nt production:true,nt youtube:'%s' n};n" "$youtube" > "$PE"
- cat "$TF"
- cat "$PE"
- ls -ld "$TP/"*
- ls -ld /tmp/*
- dpl --provider=heroku --app=$HEROKU_APP_PRODUCTION --api-key=$HEROKU_API_KEY
only:
- master
#- pwd  
#- find .
#- TP=./src/environments
#- TF="$TP/environment"
#- PE="$TP/environment.prod.ts"
# - mkdir -p "$TP"
#- printf "export const environment = { nt production:false,nt youtube:'%s' n};n" "$youtube" > "$TF"
#- printf "export const environment = { nt production:true,nt youtube:'%s' n};n" "$youtube" > "$PE"
#- cat "$TF"
# - cat "$PE"
# - cp "$TF" "$TF".ts
# - echo "youtube=$youtube" > .env
# - echo "youtube=$youtube" > .env

问题是我没有构建一个docker映像,然后部署该docker映像。我创建了Dockerfile,并从此链接执行了步骤2:https://medium.com/@nieldw/use-gitlab-ci-to-deploy-docker-images-to-heroku-4e544a3a3c38然后我添加了下面的.yml文件。我已经添加了Dockerfile和.yml文件,用于使用Gitlab Pipeline 将我的Angular应用程序部署到Heroku

image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
stages:
- build

docker-build:
stage: build
script:
- TP=./src/environments
- TF="$TP/environment.prod.ts"
- PE="$TP/environment.ts"
- mkdir -p "$TP"
- printf "export const environment = { nt production:true,nt youtube:'%s' n};n" "$youtube" > "$TF"
- printf "export const environment = { nt production:false,nt youtube:'%s' n};n" "$youtube" > "$PE"
- docker build -f Dockerfile --iidfile imageid.txt -t registry.heroku.com/youtube-search-angular/my-app .
- docker login -u _ -p $HEROKU_TOKEN registry.heroku.com
- docker push registry.heroku.com/youtube-search-angular/my-app
- apk add --no-cache curl
- echo "Docker Image ID is $(cat imageid.txt)"
- |-
curl -X PATCH https://api.heroku.com/apps/youtube-search-angular/formation --header "Content-Type: application/json" --header "Accept: application/vnd.heroku+json; version=3.docker-releases" --header "Authorization: Bearer ${HEROKU_TOKEN}" --data '{ "updates": [ { "type": "web", "docker_image": "'$(cat imageid.txt)'" } ] }'
# base image
FROM node:12.2.0
# install chrome for protractor tests
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update && apt-get install -yq google-chrome-stable
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /app/package.json
RUN npm install
RUN npm install -g @angular/cli@7.3.9
# add app
COPY . /app
RUN ng build --prod
# start app
CMD ["node", "server.js"]

相关内容

最新更新