Hi, I am creating a pipeline, and so far I've been able to to create the image and push it to docker hub.
Now I need to log in to my EC2 instance, pull the image and run it. For that I have a shell script:
#!bin/bashsudo docker psecho 'Login in to docker'aws ecr get-login-password | - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
'Fetching latest image'sudo docker pull juanibe/api:latestecho 'Stoping current container'sudo docker stop cont_docker_app_test
echo 'Removing old container'sudo docker rm cont_docker_app_test-old
echo 'Rename stoped container'
sudo docker rename cont_docker_app_test cont_docker_app_test_old
echo 'Starting new container'sudo docker run -d --name cont_docker_app_test -p 443:3333 -p 8001:8001 --link my-mongo-testing:my-mongo-testing juanibe/api:latest
And I have this yml file for bitbucket:
pipelines: default: - step: services: - docker script: - export IMAGE_NAME=juanibe/vinimayapi:$BITBUCKET_COMMIT - docker build -t $IMAGE_NAME . - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD - docker push $IMAGE_NAME
Where can I run the script??
Hi @Juan Ignacio Benito and welcome to the community.
One option is to commit and push your script to your repository, and then include in the yml file a command to execute this script.
The other option is to add the commands of your script in your yml file.
For both options, you can either do this on the existing step and script in your yml file, or you can add a second step and add the commands there.
Just a note that you'll need to remove 'sudo' from the script/commands. You can't use sudo in Pipelines and you don't need to, as when you are running the image you are root.
If you have any questions, please feel free to let us know!
Thank you very much Theodora! It worked as expected.
I have one question left.
I need to add environment variables (the ones that I have in the .env file) for the source code. Is there any way to hide them and use them without commiting the .env file to the repo?
Thank you again!
You are very welcome, I'm glad to hear that this worked!
Regarding variables, you can add variables either from the Repository settings ( > option Repository variables in the Pipelines section), if you want them to be available for this repo only, or at the workspace level (from workspace Settings > Workspace variables), if you want them to be available in all repos of this workspace.
When you create a variable you'll see a checkbox with the label Secured. If you select that, the variable's value won't be visible (and if you attempt to print it during the Pipelines build, its value still won't be shown).
Is this something that works for you?
...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events