Docker изображений не отправляются в ECR - PullRequest
0 голосов
/ 23 марта 2020

У меня странная проблема. Я помещаю Docker изображений в ECR. 2 из 4 изображений нажаты. Другие 2 по какой-то причине опущены.

Мой файл pu sh:

 if [ "$GITLAB_BRANCH" == "staging" ] || \
     [ "$GITLAB_BRANCH" == "production" ]
    then
    docker build $USERS_REPO -t $USERS:$COMMIT -f Dockerfile-$DOCKER_ENV
    docker tag $USERS:$COMMIT $REPO/$USERS:$TAG
    docker push $REPO/$USERS:$TAG         #<-- SUCCESSFULLY PUSHED

    docker build $USERS_DB_REPO -t $USERS_DB:$COMMIT -f Dockerfile
    docker tag $USERS_DB:$COMMIT $REPO/$USERS_DB:$TAG
    docker push $REPO/$USERS_DB:$TAG      #<-- SUCCESSFULLY PUSHED

    docker build $CLIENT_REPO -t $CLIENT:$COMMIT -f Dockerfile-prod --build-arg REACT_APP_USERS_SERVICE_URL=""
    echo "CLIENT 1st LINE EXECUTED"                 #  NOT EXECUTED
    docker tag $CLIENT:$COMMIT $REPO/$CLIENT:$TAG   #  NOT EXECUTED
    echo "CLIENT 2nd LINE EXECUTED"                 #  NOT EXECUTED
    docker push $REPO/$CLIENT:$TAG                  #  NOT EXECUTED

    docker build $SWAGGER_REPO -t $SWAGGER:$COMMIT -f Dockerfile-$DOCKER_ENV  #  NOT EXECUTED
    docker tag $SWAGGER:$COMMIT $REPO/$SWAGGER:$TAG                           #  NOT EXECUTED
    docker push $REPO/$SWAGGER:$TAG                                           #  NOT EXECUTED
  fi

Благодаря этим отладочным операторам эха я определил, что команды Client и Swagger не являются выполняется.

журнал заданий (только совместное использование релевантных выходных данных):

Login Succeeded
Step 1/9 : FROM python:3.8.2-slim
---> ee07b1466448
Step 2/9 : RUN apt-get update && apt-get -y install netcat && apt-get clean
---> Using cache
---> b0a678c8b22d
Step 3/9 : WORKDIR /usr/src/app
---> Using cache
---> 25d4353ddd2c
Step 4/9 : COPY ./requirements.txt /usr/src/app/requirements.txt
---> 401a5620bb76
Step 5/9 : RUN pip install -r requirements.txt
---> Running in 86fac0967146
Collecting Werkzeug==0.16.1
Downloading Werkzeug-0.16.1-py2.py3-none-any.whl (327 kB)
Collecting coverage==4.5.3
Downloading coverage-4.5.3.tar.gz (384 kB)
Collecting flake8===3.7.7
Downloading flake8-3.7.7-py2.py3-none-any.whl (68 kB)
Collecting Flask==1.1.1
Downloading Flask-1.1.1-py2.py3-none-any.whl (94 kB)
Collecting flask-bcrypt==0.7.1
Downloading Flask-Bcrypt-0.7.1.tar.gz (5.1 kB)
Collecting flask-cors==3.0.7
Downloading Flask_Cors-3.0.7-py2.py3-none-any.whl (13 kB)
Collecting flask-debugtoolbar==0.10.1
Downloading Flask_DebugToolbar-0.10.1-py2.py3-none-any.whl (326 kB)
Collecting flask-migrate==2.4.0
Downloading Flask_Migrate-2.4.0-py2.py3-none-any.whl (13 kB)
Collecting Flask-RESTful==0.3.7
Downloading Flask_RESTful-0.3.7-py2.py3-none-any.whl (24 kB)
Collecting Flask-SQLAlchemy==2.3.2
Downloading Flask_SQLAlchemy-2.3.2-py2.py3-none-any.whl (16 kB)
Collecting Flask-Testing==0.7.1
Downloading Flask-Testing-0.7.1.tar.gz (43 kB)
Collecting gunicorn==20.0.4
Downloading gunicorn-20.0.4-py2.py3-none-any.whl (77 kB)
Collecting psycopg2-binary==2.8.4
Downloading psycopg2_binary-2.8.4-cp38-cp38-manylinux1_x86_64.whl (3.0 MB)
Collecting pyjwt==1.7.1
Downloading PyJWT-1.7.1-py2.py3-none-any.whl (18 kB)
Collecting pyflakes<2.2.0,>=2.1.0
Downloading pyflakes-2.1.1-py2.py3-none-any.whl (59 kB)
Collecting entrypoints<0.4.0,>=0.3.0
Downloading entrypoints-0.3-py2.py3-none-any.whl (11 kB)
Collecting pycodestyle<2.6.0,>=2.5.0
Downloading pycodestyle-2.5.0-py2.py3-none-any.whl (51 kB)
Collecting mccabe<0.7.0,>=0.6.0
Downloading mccabe-0.6.1-py2.py3-none-any.whl (8.6 kB)
Collecting click>=5.1
Downloading click-7.1.1-py2.py3-none-any.whl (82 kB)
Collecting itsdangerous>=0.24
Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)
Collecting Jinja2>=2.10.1
Downloading Jinja2-2.11.1-py2.py3-none-any.whl (126 kB)
Collecting bcrypt
Downloading bcrypt-3.1.7-cp34-abi3-manylinux1_x86_64.whl (56 kB)
Collecting Six
Downloading six-1.14.0-py2.py3-none-any.whl (10 kB)
Collecting Blinker
Downloading blinker-1.4.tar.gz (111 kB)
Collecting alembic>=0.7
Downloading alembic-1.4.2.tar.gz (1.1 MB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing wheel metadata: started
Preparing wheel metadata: finished with status 'done'
Collecting aniso8601>=0.82
Downloading aniso8601-8.0.0-py2.py3-none-any.whl (43 kB)
Collecting pytz
Downloading pytz-2019.3-py2.py3-none-any.whl (509 kB)
Collecting SQLAlchemy>=0.8.0
Downloading SQLAlchemy-1.3.15.tar.gz (6.1 MB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing wheel metadata: started
Preparing wheel metadata: finished with status 'done'
Requirement already satisfied: setuptools>=3.0 in /usr/local/lib/python3.8/site-packages (from gunicorn==20.0.4->-r requirements.txt (line 12)) (45.2.0)
Collecting MarkupSafe>=0.23
Downloading MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl (32 kB)
Collecting cffi>=1.1
Downloading cffi-1.14.0-cp38-cp38-manylinux1_x86_64.whl (409 kB)
Collecting python-editor>=0.3
Downloading python_editor-1.0.4-py3-none-any.whl (4.9 kB)
Collecting python-dateutil
Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Collecting Mako
Downloading Mako-1.1.2-py2.py3-none-any.whl (75 kB)
Collecting pycparser
Downloading pycparser-2.20-py2.py3-none-any.whl (112 kB)
Building wheels for collected packages: coverage, flask-bcrypt, Flask-Testing, Blinker, alembic, SQLAlchemy
Building wheel for coverage (setup.py): started
Building wheel for coverage (setup.py): finished with status 'done'
Created wheel for coverage: filename=coverage-4.5.3-py3-none-any.whl size=170336 sha256=038d3ae43b6607fdfd80e1d69f79420bd823507f7be1fc20bdd16d2cdf01d518
Stored in directory: /root/.cache/pip/wheels/b0/4c/d7/9db997336a1ea6749f3b3b1b9edea6f6665ee86f58ae1e5b1b
Building wheel for flask-bcrypt (setup.py): started
Building wheel for flask-bcrypt (setup.py): finished with status 'done'
Created wheel for flask-bcrypt: filename=Flask_Bcrypt-0.7.1-py3-none-any.whl size=5010 sha256=62300cc512e7c33a42f41ca20120672f7b6ff54c5009a208c32b3fc50bf4da62
Stored in directory: /root/.cache/pip/wheels/8a/d9/0e/dc762c4ebc76f581397a2e25991db6efd148640b5616ab9210
Building wheel for Flask-Testing (setup.py): started
Building wheel for Flask-Testing (setup.py): finished with status 'done'
Created wheel for Flask-Testing: filename=Flask_Testing-0.7.1-py3-none-any.whl size=8167 sha256=972152da9797e69bc3682dd259120d95076afdf31e1f3f6dca9e68cb745b84f8
Stored in directory: /root/.cache/pip/wheels/1e/61/04/028fc73af661e18862396627606c5898a5da45f13ac0e37711
Building wheel for Blinker (setup.py): started
Building wheel for Blinker (setup.py): finished with status 'done'
Created wheel for Blinker: filename=blinker-1.4-py3-none-any.whl size=13452 sha256=bba96e4a53181a424212eaa71d27e74fa0d13c3914867e58b0484a0a60ecd377
Stored in directory: /root/.cache/pip/wheels/b7/a5/68/fe632054a5eadd531c7a49d740c50eb6adfbeca822b4eab8d4
Building wheel for alembic (PEP 517): started
Building wheel for alembic (PEP 517): finished with status 'done'
Created wheel for alembic: filename=alembic-1.4.2-py2.py3-none-any.whl size=159543 sha256=298ba2526878708a54b8db0ad2ab5ef05be4438963dd09bec1a50b59c8a15508
Stored in directory: /root/.cache/pip/wheels/70/08/70/cea787a7e95817b831469fa42af076046e55a05f7c94657463
Building wheel for SQLAlchemy (PEP 517): started
Building wheel for SQLAlchemy (PEP 517): finished with status 'done'
Created wheel for SQLAlchemy: filename=SQLAlchemy-1.3.15-cp38-cp38-linux_x86_64.whl size=1183124 sha256=50418d7071fd37b2db91f19a375389422fdc56895072af53df4a6665537d893b
Stored in directory: /root/.cache/pip/wheels/d1/0c/78/33448c81fd8e458d60897744f30462ca39e682637ec9591c0d
Successfully built coverage flask-bcrypt Flask-Testing Blinker alembic SQLAlchemy
Installing collected packages: Werkzeug, coverage, pyflakes, entrypoints, pycodestyle, mccabe, flake8, click, itsdangerous, MarkupSafe, Jinja2, Flask, pycparser, cffi, Six, bcrypt, flask-bcrypt, flask-cors, Blinker, flask-debugtoolbar, SQLAlchemy, python-editor, python-dateutil, Mako, alembic, Flask-SQLAlchemy, flask-migrate, aniso8601, pytz, Flask-RESTful, Flask-Testing, gunicorn, psycopg2-binary, pyjwt
Successfully installed Blinker-1.4 Flask-1.1.1 Flask-RESTful-0.3.7 Flask-SQLAlchemy-2.3.2 Flask-Testing-0.7.1 Jinja2-2.11.1 Mako-1.1.2 MarkupSafe-1.1.1 SQLAlchemy-1.3.15 Six-1.14.0 Werkzeug-0.16.1 alembic-1.4.2 aniso8601-8.0.0 bcrypt-3.1.7 cffi-1.14.0 click-7.1.1 coverage-4.5.3 entrypoints-0.3 flake8-3.7.7 flask-bcrypt-0.7.1 flask-cors-3.0.7 flask-debugtoolbar-0.10.1 flask-migrate-2.4.0 gunicorn-20.0.4 itsdangerous-1.1.0 mccabe-0.6.1 psycopg2-binary-2.8.4 pycodestyle-2.5.0 pycparser-2.20 pyflakes-2.1.1 pyjwt-1.7.1 python-dateutil-2.8.1 python-editor-1.0.4 pytz-2019.3
Removing intermediate container 86fac0967146
---> 24e9fd372978
Step 6/9 : COPY ./entrypoint.sh /usr/src/app/entrypoint-prod.sh
---> a8a8ff286b9a
Step 7/9 : RUN chmod +x /usr/src/app/entrypoint-prod.sh
---> Running in 3e5271e99947
Removing intermediate container 3e5271e99947
---> ed979b6a92d2
Step 8/9 : COPY . /usr/src/app
---> 98ae33e1a57f
Step 9/9 : CMD ["/usr/src/app/entrypoint-prod.sh"]
---> Running in 47ec0411fa6f
Removing intermediate container 47ec0411fa6f
---> aa4f69380842
Successfully built aa4f69380842
Successfully tagged test-driven-users:7cd9fc49
The push refers to repository [274725968600.dkr.ecr.eu-west-2.amazonaws.com/test-driven-users]
84b82b2ee3ff: Preparing
863cf2890ceb: Preparing
863cf2890ceb: Preparing
71378740a723: Preparing
116445b56805: Preparing
3e98b52f064e: Preparing
241d1d8b8b7e: Preparing
fe108eef54ea: Preparing
df4dc71f749c: Preparing
64b4e3ecc0d6: Preparing
bdc3a0723efa: Preparing
f2cb0ecef392: Preparing
241d1d8b8b7e: Waiting
fe108eef54ea: Waiting
df4dc71f749c: Waiting
64b4e3ecc0d6: Waiting
bdc3a0723efa: Waiting
f2cb0ecef392: Waiting
116445b56805: Pushed
863cf2890ceb: Pushed
84b82b2ee3ff: Pushed
3e98b52f064e: Pushed
df4dc71f749c: Layer already exists
64b4e3ecc0d6: Layer already exists
fe108eef54ea: Layer already exists
bdc3a0723efa: Layer already exists
f2cb0ecef392: Layer already exists
71378740a723: Pushed
241d1d8b8b7e: Pushed
production: digest: sha256:f14a77a6e8555ecb29c5d7cd1b1435f2835e43c483ae530ec7e877974bc6b32a size: 2830
Users pushed
Step 1/2 : FROM postgres:12.2-alpine
---> 155381193772
Step 2/2 : ADD create.sql /docker-entrypoint-initdb.d
---> 21a0338e2cd6
Successfully built 21a0338e2cd6
Successfully tagged test-driven-users_db:7cd9fc49
The push refers to repository [274725968600.dkr.ecr.eu-west-2.amazonaws.com/test-driven-users_db]
0d9977ee4514: Preparing
2552a4140be9: Preparing
4a517dd4afb0: Preparing
08185ac708af: Preparing
8c2dd7a8ecdf: Preparing
230e876ebf83: Preparing
fe9df245e483: Preparing
e384dedb3f12: Preparing
5216338b40a7: Preparing
230e876ebf83: Waiting
fe9df245e483: Waiting
e384dedb3f12: Waiting
5216338b40a7: Waiting
2552a4140be9: Layer already exists
4a517dd4afb0: Layer already exists
08185ac708af: Layer already exists
8c2dd7a8ecdf: Layer already exists
230e876ebf83: Layer already exists
fe9df245e483: Layer already exists
e384dedb3f12: Layer already exists
5216338b40a7: Layer already exists
0d9977ee4514: Pushed
production: digest: sha256:8ff80fd2a71f71524ea3c293094099c6d110ad60c5118654bd899a1ef78f8b8f size: 2192
Database pushed
Step 1/20 : FROM node:11.12.0-alpine as builder
---> 09084e4ff58d
Step 2/20 : WORKDIR /usr/src/app
---> Using cache
---> 2a5d0819135f
Step 3/20 : RUN apk add --no-cache --virtual .gyp python make g++
---> Using cache
---> 56864a4e5367
Step 4/20 : ENV PATH /usr/src/app/node_modules/.bin:$PATH
---> Using cache
---> 0e0bf35b6ecc
Step 5/20 : COPY package.json /usr/src/app/package.json
---> 8616da17869a
Step 6/20 : COPY package-lock.json /usr/src/app/package-lock.json
---> 7d43a249c366
Step 7/20 : RUN npm install --no-optional
---> Running in 11527112e824
> cypress@4.1.0 postinstall /usr/src/app/node_modules/cypress
> node index.js --exec install
Installing Cypress (version: 4.1.0)
[11:00:49] Downloading Cypress [started]
[11:00:49] Downloading Cypress 0% 0s [title changed]
…
…

[11:00:51] Downloading Cypress 83% 0s [title changed]
[11:00:51] Downloading Cypress 98% 0s [title changed]
[11:00:52] Downloaded Cypress [title changed]
[11:00:52] Downloaded Cypress [completed]
[11:00:52] Unzipping Cypress [started]
[11:00:53] Unzipping Cypress 0% 0s [title changed]
[11:00:54] Unzipping Cypress 1% 161s [title changed]
[11:00:54] Unzipping Cypress 1% 162s [title changed]
[11:00:54] Unzipping Cypress 1% 163s [title changed]
[11:00:55] Unzipping Cypress 1% 334s [title changed]
[11:00:55] Unzipping Cypress 1% 335s [title changed]
…
…

[11:01:06] Unzipping Cypress 9% 140s [title changed]
[11:01:08] Unzipping Cypress 9% 164s [title changed]
[11:01:08] Unzipping Cypress 100% 0s [title changed]
[11:01:08] Unzipped Cypress [title changed]
[11:01:08] Unzipped Cypress [completed]
[11:01:08] Finishing Installation [started]
[11:01:08] Finished Installation /root/.cache/Cypress/4.1.0 [title changed]
[11:01:08] Finished Installation /root/.cache/Cypress/4.1.0 [completed]
You can now open Cypress by running: node_modules/.bin/cypress open
https://on.cypress.io/installing-cypress
added 2034 packages from 768 contributors and audited 38602 packages in 76.256s
found 1073 vulnerabilities (1058 low, 14 moderate, 1 high)
run `npm audit fix` to fix them, or `npm audit` for details
Saving cache 
00:02 
Uploading artifacts for successful job 
00:02 
Job succeeded

Как вы можете видеть, он завершается с «Заданием выполнено успешно» без ошибок, указывающих, почему он не смог запустить другие 2 docker изображения.

Есть предложения?

Обновление:

, включая set -euo pipefail, выявлено: line 4: GITLAB_PULL_REQUEST: unbound variable

соответствующий код:

#!/bin/sh
set -euo pipefail

if [ -z "$GITLAB_PULL_REQUEST" ] || [ "$GITLAB_PULL_REQUEST" == "false" ]  # <-- LINE 4
then
  if [[ "$GITLAB_BRANCH" == "staging" ]]; then
    export DOCKER_ENV=stage
  elif [[ "$GITLAB_BRANCH" == "production" ]]; then
    export DOCKER_ENV=prod
  fi

  if [ "$GITLAB_BRANCH" == "staging" ] || \
     [ "$GITLAB_BRANCH" == "production" ]
  then
    ...
    ...

1 Ответ

0 голосов
/ 23 марта 2020

Вы предполагаете, что сценарий оболочки остановится, если один из шагов завершится неудачей. К сожалению, сценарии оболочки этого не делают: они с радостью продолжат работу, даже если команда не будет выполнена.

Так что может случиться так, что один из этапов сборки завершится неудачей.

Для bash, вы можете сделать set -euo pipefail, чтобы получить немного более разумное поведение. Подробнее см. http://redsymbol.net/articles/unofficial-bash-strict-mode/.

...