I was able to build and push image to the container registry.But somehow when it comes to deploy section, it cannot deploy successfully. Also something starnge is what I can see from Contrl plane UI and after ssh into the server is totally different. Even there’s command that delete old image it can be deleted from control plane, but from inside the droplet, it still has multi images with new tag names. Also I successfully installed docker and can see from github pipeline, but from the server it shows no docker. Could someone point out me to the right directrion?
jobs: build_and_push: runs-on: ubuntu-latest steps: - name: Checkout the repo uses: actions/checkout@v2
- name: Build container image
run: docker build -t $(echo $REGISTRY)/$(echo $IMAGE_NAME):$(echo $GITHUB_SHA | head -c7) .
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Log in to DigitalOcean Container Registry with short-lived credentials
run: doctl registry login --expiry-seconds 600
- name: Remove all old images
run: if [ ! -z "$(doctl registry repository list | grep "$(echo $IMAGE_NAME)")" ]; then doctl registry repository delete-manifest $(echo $IMAGE_NAME) $(doctl registry repository list-tags $(echo $IMAGE_NAME) | grep -o "sha.*") --force; else echo "No repository"; fi
- name: Push image to DigitalOcean Container Registry
run: docker push $(echo $REGISTRY)/$(echo $IMAGE_NAME):$(echo $GITHUB_SHA | head -c7)
- name: Run registry garbage collection
run: doctl registry garbage-collection start --include-untagged-manifests --force
deploy: runs-on: ubuntu-latest needs: build_and_push
steps:
- name: Install Docker/
uses: docker-practice/actions-setup-docker@master
timeout-minutes: 12
- name: Deploy to Digital Ocean droplet via SSH action
uses: appleboy/ssh-action@v0.1.3
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSHKEY }}
envs: IMAGE_NAME,REGISTRY,{{ secrets.DIGITALOCEAN_ACCESS_TOKEN }},GITHUB_SHA
script: |
# Login to registry
docker login -u ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} -p ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} registry.digitalocean.com
# Stop running container
docker stop $(echo $IMAGE_NAME)
# Remove old container
docker rm $(echo $IMAGE_NAME)
# Run a new container from a new image
docker run -d \
--restart always \
--name $(echo $IMAGE_NAME) \
$(echo $REGISTRY)/$(echo $IMAGE_NAME):$(echo $GITHUB_SHA | head -c7)
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hi there,
This is quite strange, if you’re seeing inconsistencies between what GitHub Actions reports and what you see on the Droplet, ensure that Docker is correctly installed and running on the Droplet.
You can verify this by logging into the Droplet via SSH and running
docker --version
. If Docker isn’t installed, you’ll need to install it on the server itself:If there are differences between the Control Plane UI and the actual state inside the Droplet, it could be a synchronization or caching issue:
Regarding the GitHub workflow, what I could suggest here is to add more verbose logging to your SSH script commands to track each step’s execution and output. That way you could get more information on what might be happening and where things might be failing.
Let me know how it goes!
Best,
Bobby