Skip to content

Automated Bash script to deploy Dockerized applications on a remote Ubuntu Linux server, including setup, container orchestration, and Nginx reverse proxy configuration.

Notifications You must be signed in to change notification settings

Fabito97/auto-deploy-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Deploy Script for Dockerized Application

Overview

This repository contains a production-ready Bash script (deploy.sh) that automates the setup, deployment, and configuration of a Dockerized application on a remote Linux server. It is designed to handle every step from collecting credentials to validating the deployment, with full logging and error handling.

The script is intended to simplify the deployment workflow, ensure repeatable results, and maintain idempotency.

Features

  • Interactive first-time setup to collect and validate environment variables.

  • Supports both HTTPS (with Personal Access Token) and SSH Git repositories.

  • Automatic cloning or pulling of the repository.

  • Detection and validation of Dockerfile or docker-compose.yml.

  • SSH connectivity verification and remote command execution.

  • Remote server preparation:

    • Update system packages
    • Install Docker, Docker Compose, and Nginx if missing
    • Add user to Docker group
    • Enable and start services
  • Deployment of Dockerized application using docker or docker-compose.

  • Transfer of project files to remote server using rsync.

  • Dynamic Nginx reverse proxy configuration.

  • Health checks to ensure container and service availability.

  • Logging of all actions with timestamped log files.

  • Support for optional flags:

    • --debug for pausing between steps
    • --cleanup to remove deployed resources
    • --reconfigure to recreate environment variables

Usage

Prerequisites

  • A remote Linux server (Ubuntu/Debian recommended).
  • SSH access to the server.
  • Git repository URL (HTTPS or SSH) for the application.
  • Bash shell locally and on the remote server.
  • Optional: Personal Access Token (PAT) for private repositories.

Running the Script

Make the script executable:

chmod +x deploy.sh

Execute the script:

./deploy.sh

Optional flags:

  • --debug — pauses after each major step for visualization.
  • --cleanup — removes deployed containers and Nginx configuration.
  • --reconfigure — re-runs environment variable setup.

Example:

./deploy.sh --debug

Environment Variables

The script stores environment configuration in .deploy.env. This includes:

  • GIT_REPO — Git repository URL
  • PAT — Personal Access Token (for HTTPS private repos)
  • BRANCH — Git branch to deploy
  • SSH_USER — SSH username for remote server
  • SERVER_IP — Remote server IP address or hostname
  • SSH_KEY — Path to private SSH key
  • APP_PORT — Internal container port

Deployment Steps

  1. Collect Parameters: Prompts user for Git repo, PAT, branch, SSH credentials, and app port.
  2. Clone Repository: Clones or updates the local repository and checks out the specified branch.
  3. Validate Project: Checks for Dockerfile or docker-compose.yml.
  4. Test SSH: Ensures connectivity to the remote server.
  5. Prepare Remote Environment: Updates packages and installs required services.
  6. Transfer & Deploy: Uses rsync to transfer project files and runs Docker containers.
  7. Configure Nginx: Sets up a reverse proxy to forward HTTP traffic to the container port.
  8. Health Checks: Verifies Docker service, running containers, Nginx status, and endpoint availability.
  9. Logging & Error Handling: All steps logged; traps handle errors and exit codes.
  10. Idempotency & Cleanup: Ensures safe re-runs and optionally cleans up deployed resources.

Logs

All output is logged to a timestamped log file, e.g., deploy_YYYYMMDD_HHMMSS.LOG, located in the same directory as the script.

Notes

  • The script assumes Ubuntu/Debian for remote server package management. Other distributions require adjusting package installation commands.
  • It avoids configuration management tools; everything is handled via Bash and SSH.
  • .deploy.env is automatically gitignored.

About

Automated Bash script to deploy Dockerized applications on a remote Ubuntu Linux server, including setup, container orchestration, and Nginx reverse proxy configuration.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages