Skip to content

Commit 66306db

Browse files
committed
init: add docker and package build
0 parents  commit 66306db

File tree

10 files changed

+686
-0
lines changed

10 files changed

+686
-0
lines changed

.github/workflows/build-debian.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Build Debian Package
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
branches:
12+
- main
13+
- master
14+
workflow_dispatch:
15+
16+
jobs:
17+
build-deb:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write
21+
packages: read
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
30+
- name: Log in to GitHub Container Registry
31+
uses: docker/login-action@v3
32+
with:
33+
registry: ghcr.io
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Set package version
38+
id: version
39+
run: |
40+
if [[ $GITHUB_REF == refs/tags/v* ]]; then
41+
VERSION=${GITHUB_REF#refs/tags/v}
42+
else
43+
VERSION="1.0.0-dev+$(git rev-parse --short HEAD)"
44+
fi
45+
echo "version=$VERSION" >> $GITHUB_OUTPUT
46+
echo "Package version: $VERSION"
47+
48+
- name: Update version in control file
49+
run: |
50+
sed -i "s/^Version:.*/Version: ${{ steps.version.outputs.version }}/" debian/DEBIAN/control
51+
52+
- name: Build Debian package (without image)
53+
run: make build
54+
55+
- name: Rename package (without image)
56+
run: |
57+
mv swarm-cli_*.deb swarm-cli_${{ steps.version.outputs.version }}_all.deb
58+
59+
- name: Build Debian package (with bundled image)
60+
run: make build-with-image
61+
62+
- name: Rename package (with image)
63+
run: |
64+
mv swarm-cli_*.deb swarm-cli_${{ steps.version.outputs.version }}_all-with-image.deb
65+
66+
- name: Upload Debian packages as artifacts
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: swarm-cli-deb-packages
70+
path: "*.deb"
71+
retention-days: 90
72+
73+
- name: Create Release and Upload Assets
74+
if: startsWith(github.ref, 'refs/tags/v')
75+
uses: softprops/action-gh-release@v1
76+
with:
77+
files: |
78+
swarm-cli_${{ steps.version.outputs.version }}_all.deb
79+
swarm-cli_${{ steps.version.outputs.version }}_all-with-image.deb
80+
draft: false
81+
prerelease: false
82+
body: |
83+
## Swarm CLI Release ${{ steps.version.outputs.version }}
84+
85+
### Installation Options
86+
87+
**Option 1: Lightweight package (recommended)**
88+
- Download: `swarm-cli_${{ steps.version.outputs.version }}_all.deb`
89+
- Size: ~10KB
90+
- Requires internet connection to pull Docker image on first use
91+
92+
**Option 2: Self-contained package**
93+
- Download: `swarm-cli_${{ steps.version.outputs.version }}_all-with-image.deb`
94+
- Size: ~50-100MB
95+
- Includes bundled Docker image, no internet required
96+
- Perfect for offline/air-gapped environments
97+
98+
### Install
99+
```bash
100+
# Download your preferred package
101+
wget https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/swarm-cli_${{ steps.version.outputs.version }}_all.deb
102+
103+
# Install
104+
sudo apt install ./swarm-cli_${{ steps.version.outputs.version }}_all.deb
105+
```
106+
107+
### Usage
108+
```bash
109+
swarm-cli --help
110+
swarm-cli status
111+
```
112+
env:
113+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
branches:
12+
- main
13+
- master
14+
workflow_dispatch:
15+
16+
env:
17+
REGISTRY: ghcr.io
18+
IMAGE_NAME: ${{ github.repository }}
19+
20+
jobs:
21+
build-and-push:
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: read
25+
packages: write
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Log in to GitHub Container Registry
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ${{ env.REGISTRY }}
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Extract metadata (tags, labels) for Docker
42+
id: meta
43+
uses: docker/metadata-action@v5
44+
with:
45+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
46+
tags: |
47+
type=ref,event=branch
48+
type=ref,event=pr
49+
type=semver,pattern={{version}}
50+
type=semver,pattern={{major}}.{{minor}}
51+
type=semver,pattern={{major}}
52+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }}
53+
54+
- name: Build and push Docker image
55+
uses: docker/build-push-action@v5
56+
with:
57+
context: .
58+
file: ./Dockerfile
59+
push: ${{ github.event_name != 'pull_request' }}
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Docker
2+
*.log
3+
4+
# Build artifacts
5+
build/
6+
*.deb
7+
8+
# OS
9+
.DS_Store
10+
Thumbs.db
11+
12+
# IDE
13+
.vscode/
14+
.idea/

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM node:24-alpine
2+
3+
RUN npm install -g @ethersphere/swarm-cli
4+
5+
ENTRYPOINT ["swarm-cli"]
6+
CMD ["--help"]

Makefile

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
.PHONY: all build build-with-image clean install uninstall help
2+
3+
# Package configuration
4+
PACKAGE_NAME := swarm-cli
5+
VERSION := 1.0.0
6+
ARCHITECTURE := all
7+
BUILD_DIR := build
8+
DEB_FILE := $(PACKAGE_NAME)_$(VERSION)_$(ARCHITECTURE).deb
9+
PACKAGE_DIR := $(BUILD_DIR)/$(PACKAGE_NAME)
10+
DOCKER_IMAGE := ghcr.io/metaprovide/swarm-cli:latest
11+
DOCKER_IMAGE_TAR := swarm-cli-docker-image.tar.gz
12+
13+
# Colors for output
14+
GREEN := \033[0;32m
15+
BLUE := \033[0;34m
16+
YELLOW := \033[0;33m
17+
NC := \033[0m
18+
19+
all: build
20+
21+
help:
22+
@echo "$(BLUE)Swarm CLI Debian Package Makefile$(NC)"
23+
@echo ""
24+
@echo "Available targets:"
25+
@echo " $(GREEN)make build$(NC) - Build the Debian package (without Docker image)"
26+
@echo " $(GREEN)make build-with-image$(NC) - Build package with bundled Docker image"
27+
@echo " $(GREEN)make clean$(NC) - Clean build artifacts"
28+
@echo " $(GREEN)make install$(NC) - Install the package (requires sudo)"
29+
@echo " $(GREEN)make uninstall$(NC) - Uninstall the package (requires sudo)"
30+
@echo " $(GREEN)make help$(NC) - Show this help message"
31+
@echo ""
32+
33+
build: clean
34+
@echo "$(BLUE)Building $(PACKAGE_NAME) Debian package (without Docker image)...$(NC)"
35+
@echo "Creating package structure..."
36+
@mkdir -p $(PACKAGE_DIR)
37+
38+
@echo "Copying package files..."
39+
@cp -r debian/* $(PACKAGE_DIR)/
40+
41+
@echo "Setting permissions..."
42+
@chmod 755 $(PACKAGE_DIR)/DEBIAN
43+
@chmod 755 $(PACKAGE_DIR)/DEBIAN/postinst
44+
@chmod 755 $(PACKAGE_DIR)/DEBIAN/prerm
45+
@chmod 755 $(PACKAGE_DIR)/usr/bin/swarm-cli
46+
47+
@echo "Building .deb package..."
48+
@dpkg-deb --build $(PACKAGE_DIR) $(BUILD_DIR)/$(DEB_FILE)
49+
50+
@echo "Moving package to root directory..."
51+
@mv $(BUILD_DIR)/$(DEB_FILE) .
52+
53+
@echo "$(GREEN)✓ Package built successfully: $(DEB_FILE)$(NC)"
54+
@echo ""
55+
@echo "To install the package, run:"
56+
@echo " $(BLUE)make install$(NC)"
57+
@echo ""
58+
59+
build-with-image: clean
60+
@echo "$(BLUE)Building $(PACKAGE_NAME) Debian package with bundled Docker image...$(NC)"
61+
@echo "Creating package structure..."
62+
@mkdir -p $(PACKAGE_DIR)/usr/share/swarm-cli
63+
64+
@echo "Copying package files..."
65+
@cp -r debian/* $(PACKAGE_DIR)/
66+
67+
@echo "Pulling Docker image..."
68+
@docker pull $(DOCKER_IMAGE)
69+
70+
@echo "Exporting Docker image to tar.gz..."
71+
@docker save $(DOCKER_IMAGE) | gzip > $(PACKAGE_DIR)/usr/share/swarm-cli/$(DOCKER_IMAGE_TAR)
72+
73+
@echo "Setting permissions..."
74+
@chmod 755 $(PACKAGE_DIR)/DEBIAN
75+
@chmod 755 $(PACKAGE_DIR)/DEBIAN/postinst
76+
@chmod 755 $(PACKAGE_DIR)/DEBIAN/prerm
77+
@chmod 755 $(PACKAGE_DIR)/usr/bin/swarm-cli
78+
@chmod 644 $(PACKAGE_DIR)/usr/share/swarm-cli/$(DOCKER_IMAGE_TAR)
79+
80+
@echo "Building .deb package..."
81+
@dpkg-deb --build $(PACKAGE_DIR) $(BUILD_DIR)/$(DEB_FILE)
82+
83+
@echo "Moving package to root directory..."
84+
@mv $(BUILD_DIR)/$(DEB_FILE) .
85+
86+
@echo "$(GREEN)✓ Package with bundled image built successfully: $(DEB_FILE)$(NC)"
87+
@echo "$(YELLOW)Note: Package size is larger due to bundled Docker image$(NC)"
88+
@echo ""
89+
@echo "To install the package, run:"
90+
@echo " $(BLUE)make install$(NC)"
91+
@echo ""
92+
93+
clean:
94+
@echo "$(YELLOW)Cleaning build artifacts...$(NC)"
95+
@rm -rf $(BUILD_DIR)
96+
@rm -f $(PACKAGE_NAME)_*.deb
97+
@echo "$(GREEN)✓ Clean complete$(NC)"
98+
99+
install: $(DEB_FILE)
100+
@echo "$(BLUE)Installing $(DEB_FILE)...$(NC)"
101+
@sudo apt install ./$(DEB_FILE)
102+
@echo "$(GREEN)✓ Installation complete$(NC)"
103+
104+
uninstall:
105+
@echo "$(YELLOW)Uninstalling $(PACKAGE_NAME)...$(NC)"
106+
@sudo apt remove $(PACKAGE_NAME)
107+
@echo "$(GREEN)✓ Uninstall complete$(NC)"
108+
109+
$(DEB_FILE):
110+
@echo "$(YELLOW)Package not found. Building...$(NC)"
111+
@$(MAKE) build

0 commit comments

Comments
 (0)