rdsx.dev

Fri Sep 15 2023

GitHub Actions Push Docker Image via SSH

GitHub Actions Push Docker Image via SSH

This project provides an easy way to build, push and run your Docker image to your server via SSH with GitHub Actions. It automates the deployment process, ensuring that your Docker containers are up and running on the remote server.

What is GitHub Actions Push Docker Image via SSH?

This project provides a GitHub Action workflow to build and push a Docker image to a remote server using SSH. It automates the deployment process, ensuring that your Docker containers are up and running on the remote server with minimal manual intervention.

Key Features

  • Automated build and push of Docker images
  • Secure deployment via SSH
  • Easy setup with GitHub Secrets
  • Supports custom Dockerfile and docker-compose configurations
  • Streamlined workflow for continuous deployment

Prerequisites

Before using this workflow, ensure you have:

  • A Dockerfile in your repository
  • A docker-compose.yaml file for your services
  • The workflow file (deploy.yaml) in your .github/workflows directory

How to Use

  1. Generate an SSH key pair on your local machine
  2. Add the public key to your remote server's authorized_keys file
  3. Add the following secrets to your GitHub repository:
    • SSH_PRIVATE_KEY: Your SSH private key
    • REMOTE_SERVER_USERNAME: SSH username for the remote server
    • REMOTE_SERVER_ADDRESS: IP or hostname of the remote server
    • REMOTE_SERVER_PATH: Path on the remote server for the Docker Compose file
  4. Push changes to your main branch to trigger the workflow

Workflow Process

  1. The workflow is triggered on push to the main branch
  2. It builds the Docker image based on your Dockerfile
  3. The image is pushed to the remote server via SSH
  4. The docker-compose.yaml file is transferred to the specified path on the server
  5. Docker containers are deployed and run on the remote server

Benefits

By using this workflow, you can significantly simplify your deployment process and ensure consistent and reliable deployments of your Docker containers. It's especially useful for small to medium-sized projects that require quick and efficient deployment strategies.

Get Involved

We welcome contributions to improve this GitHub Action workflow. Whether you're interested in adding new features, improving documentation, or fixing bugs, your input is valuable. Visit our GitHub repository to get started.