DEV Community

Deploy a React app to DigitalOcean using Github Actions and Docker

Remy Muhire on April 06, 2020

At Pindo, we recently automated all our deployment processes by setting up continuous delivery pipelines for our repositories. This setup helped us...
Collapse
 
christianmontero profile image
Christian Montero

I' m getting an error in the deploy stage, this is the output:

======CMD======
docker stop $(docker ps -a -q)
docker login docker.pkg.github.com -u $GITHUB_USERNAME -p $GITHUB_TOKEN
docker pull docker.pkg.github.com/fredomontero/bones/bones:latest
docker run -dit -p 3001:80 docker.pkg.github.com/fredomontero/bones/bones:latest
======END======
err: bash: line 2: docker: command not found
err: bash: line 2: docker: command not found
err: bash: line 3: docker: command not found
err: bash: line 4: docker: command not found

does anybody knows what' s wrong?

Collapse
 
kenessajr profile image
Remy Muhire

Hi Christian, can you check if you have docker installed on your production server?

Collapse
 
christianmontero profile image
Christian Montero

Hi Remy, thanks for answering I already solved, the issue was that I installed docker using snap, and reading on the web I realized that snap installs everything under /snap and that is not part of the environment variable PATH.

it was a little tricky because if I ssh from my local computer to the server and then run docker it works, but it didn't work from the yml file.

so instead of running docker I had to run /snap/bin/docker

or create a symlink:

sudo ln -s /snap/bin/docker /usr/bin/docker

Thank for this post bro it's very helpful!

Collapse
 
athmakuri profile image
Susheel Athmakuri • Edited

I am getting name unknown: The expected resource was not found. while publishing to the Github Package Registry.

LOG

Successfully built 831f744bab47
Successfully tagged docker.pkg.github.com/repo_name/image_name:latest
The push refers to repository [docker.pkg.github.com/repo_name/image_name]
d4c3bfb3f5d5: Preparing
3810cc0c140f: Preparing
3e207b409db3: Preparing
** name unknown: The expected resource was not found. **

DEPLOY FILE

name: build

on:
  push:
    branches: 
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: Use Node.js 13.10
      uses: actions/setup-node@v1
      with:
        node-version: '13.10'
    - name: Publish to Github Packages Registry
      uses: elgohr/Publish-Docker-Github-Action@master
      with:
        name: github_username/repo_name/image_name
        registry: docker.pkg.github.com
        username: ${{ secrets.USERNAME_GITHUB }}
        password: ${{ secrets.githubTokenSecret }}
        dockerfile: Dockerfile-prod
Enter fullscreen mode Exit fullscreen mode

Not sure what the unknown thing is.

Collapse
 
kenessajr profile image
Remy Muhire

Hi @athmakuri ,

You're not specifying your Github username, repository name, and the Docker image name github_username/repo_name/image_name. For example, my Github username is kenessajr and my repository name and docker image are both called react-with-actions, kenessajr/react-with-actions/react-with-actions. What you have to do is editing and specifying correctly your variables.

Collapse
 
athmakuri profile image
Susheel Athmakuri • Edited

Hi Remy, Thanks for your response. Here is the actual name that I have, susheelv/arc_recipe/recipecreator for which I am getting the error.

Deploy File

    - name: Publish to Github Packages Registry
      uses: elgohr/Publish-Docker-Github-Action@master
      with:
        name: susheelv/ARCRecipes/recipecreator
        registry: docker.pkg.github.com
        username: ${{ secrets.USERNAME_GITHUB }}
        password: ${{ secrets.githubTokenSecret }}
        dockerfile: Dockerfile-prod
        tags: latest

Error

Step 10/10 : CMD ["nginx", "-g", "daemon off;"]
 ---> Running in ec67f6ce496a
Removing intermediate container ec67f6ce496a
 ---> 3c2f28dbd026
Successfully built 3c2f28dbd026
Successfully tagged docker.pkg.github.com/***/arcrecipes/recipecreator:latest
The push refers to repository [docker.pkg.github.com/***/arcrecipes/recipecreator]
91f28809782e: Preparing
3810cc0c140f: Preparing
3e207b409db3: Preparing
name unknown: The expected resource was not found.
Thread Thread
 
athmakuri profile image
Susheel Athmakuri

Nevermind. I had to use the organization's name instead of my personal username to create a package.

Collapse
 
galakhov profile image
Dmitry

Hey there, it's a nice deploy.yml file! One suggestion (from docker) is to use:
echo "$GITHUB_TOKEN" | docker login docker.pkg.github.com -u $GITHUB_USERNAME --password-stdin
instead of:
docker login docker.pkg.github.com -u $GITHUB_USERNAME -p $GITHUB_TOKEN
for the security reasons.

err: WARNING! Using -*** the CLI is insecure. Use --password-stdin.
err: WARNING! Your password will be stored unencrypted in /home/***/.docker/config.json.
err: Configure a credential helper to remove this warning. See
err: https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Enter fullscreen mode Exit fullscreen mode
Collapse
 
sadi304 profile image
Sadi Mahmud • Edited

Thanks for the article. I am having an issue here. Workflow is passed and done successfully but I have noticed the changes are not being reflected in digital ocean. Is this something related to caching of the docker package? Or are there any chances that docker package will not be updated with the latest code sometimes? Any dependencies related latest tag?

EDIT: have to use docker pull before running the docker.

Collapse
 
kenessajr profile image
Remy Muhire

Hello Sady, I just realized that I forget to add docker pull for pulling new images.

Collapse
 
daveteu profile image
Dave

question: Wouldn't running Login + Pull first be a better choice to limit down time? And to prevent failure?

docker login docker.pkg.github.com -u $GITHUB_USERNAME -p $GITHUB_TOKEN
docker pull docker.pkg.github.com/my_github_username/my_repository_name/my_image_name:latest
docker stop $(docker ps -a -q)
docker run -dit -p 80:80 docker.pkg.github.com/my_github_username/my_repository_name/my_image_name:latest

Collapse
 
eelcoverbrugge profile image
Eelco Verbrugge

Many thanks! very helpfull. Everything went well until the "Deploy package to digitalocean" step in the build when I push my branch to Github. It says "Password change required but no TTY available.". I've tried resetting the root password of the droplet, but no success. Any idea?

Collapse
 
arunkmrs profile image
Arun Kumar

Great article thanks for this. Could you also help with adding a certificate to our react app & use port https with it.

Collapse
 
kenessajr profile image
Remy Muhire

Yes definitely. I will try to update the tutorial ASAP.

Collapse
 
arunkmrs profile image
Arun Kumar

Remy Any update on making the website https

Collapse
 
reddyforcode profile image
ReddyTintaya

Use this in the Dockerfile

FROM node:alpine as build
Enter fullscreen mode Exit fullscreen mode

instead of specifying the node version

if you have error

Collapse
 
legkoletat profile image
Mikhail Kuznetcov

Next, let's add our GITHUB_USERNAME to the secrets. -

gives Failed to add secret. Name is invalid

Collapse
 
salgit profile image
Stephen Lightcap

Any token that starts with GITHUB is reserved by github and included in your build process already.

Collapse
 
robertegan profile image
RobertEgan

Remy, this was very helpful. Thank you! Thank you! Thank you!

Collapse
 
napestershine profile image
napestershine

Hey

Thanks for this nice article. I have a question though. How can I do it without docker ?

Thanks