Skip to content

Commit

Permalink
feat: initial prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarneo committed Nov 11, 2024
0 parents commit 173f541
Show file tree
Hide file tree
Showing 8 changed files with 730 additions and 0 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Release Binaries

on:
push:
tags:
- 'v*'

permissions:
contents: write
packages: write

jobs:
build:
name: Build Binaries
runs-on: ubuntu-latest
strategy:
matrix:
include:
- os: linux
arch: amd64
goos: linux
goarch: amd64
- os: linux
arch: arm64
goos: linux
goarch: arm64
- os: darwin
arch: amd64
goos: darwin
goarch: amd64
- os: darwin
arch: arm64
goos: darwin
goarch: arm64

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
cache: true

- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
go build -v -o copepod-${{ matrix.os }}-${{ matrix.arch }}
chmod +x copepod-${{ matrix.os }}-${{ matrix.arch }}
- name: Generate SHA-256
run: |
sha256sum copepod-${{ matrix.os }}-${{ matrix.arch }} > copepod-${{ matrix.os }}-${{ matrix.arch }}.sha256
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.os }}-${{ matrix.arch }}
path: |
copepod-${{ matrix.os }}-${{ matrix.arch }}
copepod-${{ matrix.os }}-${{ matrix.arch }}.sha256
retention-days: 1

release:
name: Create Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
pattern: binaries-*
merge-multiple: true

- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get version from tag
VERSION=${GITHUB_REF#refs/tags/}
# Create release notes
echo "Release $VERSION" > release_notes.md
echo "" >> release_notes.md
echo "## SHA-256 Checksums" >> release_notes.md
echo '```' >> release_notes.md
cat *.sha256 >> release_notes.md
echo '```' >> release_notes.md
# Create release and upload assets
gh release create $VERSION \
--title "Copepod $VERSION" \
--notes-file release_notes.md \
copepod-*
51 changes: 51 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Binary
copepod
copepod-*

# Build
build/
dist/

# Logs
*.log
deploy.log

# Environment files
.env*
!.env.example

# IDE directories
.idea/
.vscode/
*.swp
*.swo
*~

# Go specific
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Go workspace file
go.work

# Dependency directories
vendor/

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use the official nginx image as base
FROM nginx:alpine

# Create index.html directly in the container
RUN echo '<!DOCTYPE html>\
<html>\
<head>\
<title>Welcome to copepod</title>\
</head>\
<body>\
<div class="container">\
<h1>Welcome to Copepod!</h1>\
<p>If you see this page, the nginx web server is successfully installed and working.</p>\
<p>This page was created from within the Dockerfile.</p>\
</div>\
</body>\
</html>' > /usr/share/nginx/html/index.html

# Expose port 80
EXPOSE 80

# Start nginx in the foreground
CMD ["nginx", "-g", "daemon off;"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 [Bjarne Oeverli]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
194 changes: 194 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# Copepod: Docker Deployment Tool

⚠️ **EXPERIMENTAL PROTOTYPE** - This tool is currently in experimental stage and should be used with caution in production environments.

A simple yet powerful Go-based CLI tool for automating Docker container deployments to remote servers. This tool handles the entire deployment process including building Docker images, transferring them to remote hosts, and managing container lifecycle.

## Prerequisites

- Docker installed locally and on the remote host
- SSH access to the remote host
- SSH key-based authentication

## Installation

### Pre-built Binaries

Download the latest pre-built binary from the [releases page](https://github.com/bjarneo/copepod/releases).

Available binaries:

- Linux (AMD64): `copepod-linux-amd64`
- Linux (ARM64): `copepod-linux-arm64`
- macOS (Intel): `copepod-darwin-amd64`
- macOS (Apple Silicon): `copepod-darwin-arm64`

After downloading:

1. Verify the checksum (SHA-256):

```bash
sha256sum -c copepod-<os>-<arch>.sha256
```

2. Make the binary executable:

```bash
chmod +x copepod-<os>-<arch>
```

3. Optionally, move to your PATH:

```bash
# Example for Linux/macOS
sudo mv copepod-<os>-<arch> /usr/local/bin/copepod
```

### Building from Source

Alternatively, you can build from source:

Requirements:

- Go 1.x or higher

```bash
git clone <repository-url>
cd copepod
go build -o copepod
```

## Usage

```bash
./copepod [options]
```

### Command Line Options

| Option | Environment Variable | Default | Description |
|-----------------|---------------------|------------------|--------------------------------|
| --host | COPEPOD_HOST | | Remote host to deploy to |
| --user | COPEPOD_USER | | SSH user for remote host |
| --image | COPEPOD_IMAGE | app | Docker image name |
| --tag | COPEPOD_TAG | latest | Docker image tag |
| --platform | COPEPOD_PLATFORM | linux/amd64 | Docker platform |
| --ssh-key | SSH_KEY_PATH | | Path to SSH key |
| --container-name| CONTAINER_NAME | app | Name for the container |
| --container-port| CONTAINER_PORT | 3000 | Container port |
| --host-port | HOST_PORT | 3000 | Host port |
| --env-file | ENV_FILE | .env.production | Environment file |

### Example Commands

Basic deployment:

```bash
./copepod --host example.com --user deploy
```

Deployment with custom ports:

```bash
./copepod --host example.com --user deploy --container-name myapp --container-port 8080 --host-port 80
```

Using environment file:

```bash
./copepod --env-file .env.production
```

## Directory Structure

Your project directory should look like this:

```
.
├── Dockerfile # Required: Docker build instructions
├── your_code # Your code
└── .env.production # Optional: Environment variables
```

## Deployment Process

1. Validates configuration and checks prerequisites
2. Verifies Docker installation and SSH connectivity
3. Builds Docker image locally
4. Transfers image to remote host
5. Copies environment file (if specified)
6. Stops and removes existing container
7. Starts new container with specified configuration
8. Verifies container is running properly

## Logging

The tool maintains detailed logs in `deploy.log`, including:

- Timestamp for each operation
- Command execution details
- Success/failure status
- Error messages and stack traces

## Error Handling

The tool includes error handling for common scenarios:

- Missing Dockerfile
- SSH connection failures
- Docker build/deployment errors
- Container startup issues

## Security Considerations

- Uses SSH key-based authentication
- Supports custom SSH key paths
- Environment variables can be passed securely via env file
- No sensitive information is logged

## Known Limitations

1. Limited error recovery mechanisms
2. No rollback functionality
3. Basic container health checking
4. No support for complex Docker network configurations
5. No Docker Compose support

## Contributing

1. Fork the repository
2. Create your feature branch
3. Commit your changes
4. Push to the branch
5. Create a new Pull Request

## Release Process

New versions are automatically built and released when a new tag is pushed:

```bash
git tag v1.0.0
git push origin v1.0.0
```

This will trigger the GitHub Action workflow to:

1. Build binaries for multiple platforms
2. Generate checksums
3. Create a new release with the binaries

## TODO

- [ ] Add rollback functionality
- [ ] Improve error handling
- [ ] Add support for Docker Compose
- [ ] Implement proper container health checks
- [ ] Add shell completion support

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Disclaimer

This is an experimental prototype. Use at your own risk. The authors assume no liability for the use of this tool. Always review the code and test in a safe environment before using in any critical systems.
Binary file added demo.mp4
Binary file not shown.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module copepod

go 1.23.1
Loading

0 comments on commit 173f541

Please sign in to comment.