DEV Community

GitLab CI/CD example with a dockerized ReactJS App šŸš€

Christian Montero on August 26, 2020

Good afternoon! Today we'll be creating a CI/CD pipeline using GitLab to automate a dockerized ReactJS deployment šŸš€ Introduction So toda...
Collapse
 
duongnguyen1216 profile image
DĘ°Ę”ng Nguyį»…n • Edited

Hey, thank you very much for very detailed example.
I did it successfully and I found some point

  • The final .gitlab-ci.yml file, at deploy state, port should be 3005
  • $SSH_PRIVATE_KEY is string, not a file so we can't use chmod , I've replaced by this line
  stage: deploy
  image: kroniak/ssh-client
  before_script:
    - echo "deploying app"
  script:
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' > key.pem
    - chmod 400 key.pem
    - ssh -o StrictHostKeyChecking=no -i key.pem root@$PROD_SERVER_IP ...
    - ssh -o StrictHostKeyChecking=no -i key.pem root@$PROD_SERVER_IP ...
    - ssh -o StrictHostKeyChecking=no -i key.pem root@$PROD_SERVER_IP ...
Enter fullscreen mode Exit fullscreen mode

I used EC2 Ubuntu 18.04 Server.

Thank you again <3

Collapse
 
christianmontero profile image
Christian Montero

oh! sorry for that mistake bro! šŸ˜”
but thanks for sharing your solution this will help other devs! šŸ’Ŗ
and thank you for reading bro! šŸ‘

Collapse
 
tomasbalaz profile image
Tomas Balaz • Edited

You can set your private key gitlab variable as file and then you don't have to create key.pem file

Collapse
 
swetank01 profile image
swetank soni

I just got tricked with that error. Thanks for the fix.šŸ„³

Collapse
 
nickty profile image
nickty

Please share with us the updated code

Collapse
 
igorbuts profile image
Igor Buts • Edited

Thanks for a good and informative article. It worked for me.

Who follows the example, don't forget to make SSH_PRIVATE_KEY variable of Type: File (as it is shown on screenshot). I think it would be good to update the article and state it in the text explicitly, if possible.

Collapse
 
nickty profile image
nickty

Yes, you are right. It took my one day to solve.

Collapse
 
crjhoan profile image
Jhoan Amado

Love it, it is very detailed

Collapse
 
christianmontero profile image
Christian Montero

thanks for reading and for the feedback šŸ‘

Collapse
 
xpcrts profile image
Phok Chanrithisak • Edited

Reference link Gitlab Documentation: click here
After docker pull registry.gitlab.com/...

Output like this : Error response from daemon: pull access denied for registry.gitlab.com/..., repository does not exist or may require 'docker login': denied: requested access to the resource is denied

You need to login again using this command docker login registry.example.com -u <username_of_gitlab_account> -p <token> e.g: docker login registry.gitlab.com -u <username_of_gitlab_account> -p <token>

Token get from: Go to your gitlab profile icon > Select "Edit Profile" > on left hand side tab select "Access Tokens", then add any name on "Token name" Box for example: test-token, choose any of your "expiration date" > for "Select Scope", check all boxes > Then Click on box: "Create personal access token" > on top you will get token string,

come back to
docker login registry.example.com -u <username_of_gitlab_account> -p <token>
paste that token replace of your <token> and run on your server terminal.

Collapse
 
nickty profile image
nickty

It is expected that you will create local environment and have gitlab-yml setup for local environment. Then we could I deploy into server.
What is the use of locker docker here.
Where is Nginx working?

Please help?

Collapse
 
aimeeca20205297 profile image
Aimee Camacho

šŸ‘šŸ‘šŸ‘šŸ‘

Collapse
 
xsvato01 profile image
xsvato01

Thank you for the great tutorial! I just wonder how is the Dockerfile connected to the .gitlab-ci.yml. Why do you run npm build in the build stage of .gitlab-ci.yml when you does it already in Dockerfile?

Collapse
 
andreapigatto profile image
andreapigatto

Really nice! I think that to make more robust the production you could use docker swarm that offer nice features for example container restarting in case of down. But is more Docker thing and out of educational purpose of the post.

Collapse
 
alastrat profile image
AndrĆ©s Lastra • Edited

For some reason I'm getting this error.

I'm deploying to ec2, using de .pem key given by aws (passed as env var). But still, it doesn't work.

Collapse
 
michaelandrianai profile image
Michaƫl Andrianaivomanana

Hello there! I got issue from

ssh -o StrictHostKeyChecking=no -i $SSH_PRIVATE_KEY root@$PROD_SERVER_IP "docker pull registery_private"

It's return access denied

Collapse
 
xpcrts profile image
Phok Chanrithisak

me too