Setting up Beanstalk with Gitlab CI/CD fails when executing .sh scripts for gitlab registry user authentication

0

I am trying to get Gitlab pipelines to work with Beanstalk, but I am stuck with errors

ERROR] An error occurred during execution of command [app-deploy] - [RunAppDeployPreBuildHooks]. Stop running the command. Error: Command .platform/hooks/prebuild/01login.sh failed with error exit status 1. Stderr:.platform/hooks/prebuild/01login.sh: line 2: environment: command not found
.platform/hooks/prebuild/01login.sh: line 3: environment: command not found

I have followed this documentation: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/single-container-docker-configuration.html, I have setup chmod (btw, using Apple M1 computers there is a problem when you create .sh scripts locally, because beanstalk throws exec error,..so I created these files directly in Gitlab repository and changed chmod locally afterwards..) .

I have also created System manager variables USER and PASSWD. For deployment, I use docker-compose.yml where I have dockerfile with build instructions. Unfortunately, I cannot get to the point to get it build and run, since it fails in steps before this. Any ideas what may be wrong?

  • Hi,

    Please view my comment for the fix Thank you

已提問 2 年前檢視次數 717 次
2 個答案
0

That output looks like it's coming from your Beanstalk environment, so the good news is that your CI/CD pipeline appears to be working correctly.

It looks like you have a prebuild hook in your application bundle which is failing. Check for .platform/hooks/prebuild/01login.sh in your repo, it appears that lines 2 and 3 of this script are trying to run an environment command, but there is no such command on the Beanstalk instance. Is it possible that this script should instead be using the env command (1)?

(1) https://man7.org/linux/man-pages/man1/env.1.html

AWS
支援工程師
Wayne_G
已回答 2 年前
0

Hello,

I had the same problem when I was trying to configure docker login in my Elastic Beanstalk enviornment. I followed the document : https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/single-container-docker-configuration.html

The provided script in the document is :

01login.sh

#!/bin/bash
USER=/opt/elasticbeanstalk/bin/get-config environment -k USER
/opt/elasticbeanstalk/bin/get-config environment -k PASSWD | docker login -u $USER --password-stdin

Please update it to, 01login.sh

#!/bin/bash
USER=`/opt/elasticbeanstalk/bin/get-config environment -k USER`
/opt/elasticbeanstalk/bin/get-config environment -k PASSWD | docker login -u $USER --password-stdin

This works successfully. I have tested this out and from the eb-hooks.log

023/04/18 17:17:26.245921 [INFO] Running command .platform/hooks/prebuild/01_login.sh
2023/04/18 17:17:26.347292 [INFO] Login Succeeded

2023/04/18 17:17:26.347318 [INFO] WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

I have requested the document team to update the document. Thank you

已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南