Skip to content

Commit b71c1c8

Browse files
committed
docs(deploy-docker): update README
1 parent faa5529 commit b71c1c8

File tree

5 files changed

+128
-1
lines changed

5 files changed

+128
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ This repository contains a comprehensive collection of reusable GitHub Actions w
77
### 🐳 [Build Docker Image](./docker-build)
88
Automates the process of building, tagging, and pushing Docker images to Docker Hub. Perfect for projects that require containerization with minimal configuration overhead.
99

10+
### 🚀 [Deploy Docker](./deploy-docker)
11+
Automates the process of building a Docker image and deploying it to a remote server. Configurable for different Dockerfile paths, image names, tags, and remote hosts. Streamlines the deployment process with secure SSH connections.
12+
1013
### 📦 [Release Please](./release-please)
1114
Uses the [release-please-action](https://github.com/googleapis/release-please-action) to automate versioning and changelog generation based on Conventional Commits. This workflow streamlines your release process and ensures consistent version management.
1215

deploy-docker/CHANGELOG.md

Whitespace-only changes.

deploy-docker/README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Docker Build & Deploy - Reusable Workflow Documentation 🚀
2+
3+
## Overview 🌟
4+
5+
This reusable GitHub Actions workflow automates the process of building a Docker image and deploying it to a remote server. It is configurable via inputs for the Dockerfile path, image name, tag, remote host, and other options. The workflow performs the following actions:
6+
7+
- **Determines the Tag**: Computes the tag to use for the Docker image. 🏷️
8+
- **Builds the Docker Image**: Builds and pushes the Docker image to DockerHub. 🔨
9+
- **Deploys to Remote Server**: Securely deploys the image to a remote server using SSH. 🚀
10+
11+
## Workflow Inputs 🛠️
12+
13+
| **Input** | **Description** | **Required** | **Default** |
14+
|------------------|-----------------------------------------------------|--------------|-----------------|
15+
| **dockerfile** | Path to Dockerfile. | No | `Dockerfile` |
16+
| **image_name** | Full image name (e.g. org/my-api). | Yes | - |
17+
| **image_tag** | Optional tag override (defaults to pushed Git tag). | No | - |
18+
| **remote_host** | SSH host (user@host). | Yes | - |
19+
| **remote_path** | Remote path where compose files live. | Yes | - |
20+
| **runner_group** | Runner group or label. | No | `ubuntu-latest` |
21+
22+
### Secrets 🔐
23+
24+
| **Secret** | **Description** | **Required** |
25+
|------------------------|----------------------------------------|--------------|
26+
| **dockerhub_username** | DockerHub username for authentication. | Yes |
27+
| **dockerhub_password** | DockerHub password for authentication. | Yes |
28+
| **ssh_private_key** | SSH private key for remote deployment. | Yes |
29+
30+
### Outputs 📤
31+
32+
| **Output** | **Description** | **Value** |
33+
|------------|--------------------------------|-----------------------------------|
34+
| **tag** | Tag effectively built/deployed | `${{ jobs.get-tag.outputs.tag }}` |
35+
36+
## Jobs and Steps ⚙️
37+
38+
### Job: `get-tag`
39+
- **Purpose**: Determines the tag to use for the Docker image.
40+
- **Runs On**: The specified runner group (default: `ubuntu-latest`).
41+
- **Steps**:
42+
1. Checkout the repository.
43+
2. Compute the tag (uses the provided tag or extracts it from the Git reference).
44+
45+
### Job: `build`
46+
- **Purpose**: Builds and pushes the Docker image.
47+
- **Depends On**: `get-tag`
48+
- **Uses**: The docker-build workflow from the same repository.
49+
- **Inputs**:
50+
- Dockerfile path
51+
- Image name and tag
52+
- Push configuration (set to true)
53+
54+
### Job: `deploy`
55+
- **Purpose**: Deploys the Docker image to a remote server.
56+
- **Depends On**: `build` and `get-tag`
57+
- **Runs On**: The specified runner group.
58+
- **Steps**:
59+
1. Checkout the repository.
60+
2. Install SSH key for secure connection.
61+
3. Add remote host to known_hosts.
62+
4. Prepare .env file for Docker Compose.
63+
5. Copy compose files to the remote server.
64+
6. Pull and restart containers on the remote server.
65+
66+
## How to Use This Reusable Workflow 🔄
67+
68+
1. **Save the Workflow File**
69+
This workflow is already saved as `.github/workflows/deploy-docker.yml` in the repository. 💾
70+
71+
2. **Call the Reusable Workflow**
72+
In another workflow file (e.g., triggered by a release), invoke this reusable workflow like so:
73+
74+
```yaml
75+
name: Deploy My Docker Application
76+
on:
77+
release:
78+
types: [published]
79+
80+
jobs:
81+
deploy:
82+
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/deploy-docker.yml@main
83+
with:
84+
dockerfile: 'path/to/Dockerfile'
85+
image_name: 'your-org/your-app'
86+
remote_host: '[email protected]'
87+
remote_path: '/path/to/deployment'
88+
secrets:
89+
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
90+
dockerhub_password: ${{ secrets.DOCKERHUB_PASSWORD }}
91+
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
92+
```
93+
94+
3. **Configure Secrets**
95+
Ensure that the following secrets are added to your repository's settings:
96+
- `DOCKERHUB_USERNAME`: Your DockerHub username
97+
- `DOCKERHUB_PASSWORD`: Your DockerHub password or access token
98+
- `SSH_PRIVATE_KEY`: The SSH private key for connecting to the remote server
99+
100+
## Prerequisites 📋
101+
102+
1. **Docker Compose File**:
103+
- You must have a `docker-compose.yml` file in the root of your repository.
104+
- This file should reference the environment variables `IMAGE_NAME` and `IMAGE_TAG`.
105+
106+
2. **Remote Server**:
107+
- The remote server must have Docker and Docker Compose installed.
108+
- The user specified in `remote_host` must have permissions to run Docker commands.
109+
110+
## Workflow Steps in Detail 🔍
111+
112+
1. **Get Tag**:
113+
- Checks out the repository.
114+
- Computes the tag to use (either from the input or from the Git reference).
115+
116+
2. **Build Docker Image**:
117+
- Uses the docker-build workflow to build and push the Docker image.
118+
- Configures the image with the computed tag.
119+
120+
3. **Deploy to Remote Server**:
121+
- Sets up SSH authentication.
122+
- Prepares the environment variables file.
123+
- Copies the necessary files to the remote server.
124+
- Pulls the latest image and restarts the containers using Docker Compose.

deploy-docker/version.txt

Whitespace-only changes.

publish-npm/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ for the package scope, Node.js version, registry URL, and other options. The wor
7474

7575
jobs:
7676
publish:
77-
uses: your-org/your-repo/.github/workflows/publish-npm.yml@main
77+
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/publish-npm.yml@main
7878
with:
7979
node-version: '22'
8080
build-command: 'npm run build:prod'

0 commit comments

Comments
 (0)