Skip to content

Commit 3437bc9

Browse files
authored
Merge pull request #187 from AzureCosmosDB/copilot/fix-148
Add Docker container support for CI/CD pipelines
2 parents 7d5db84 + 3f87b71 commit 3437bc9

File tree

8 files changed

+230
-1
lines changed

8 files changed

+230
-1
lines changed

.dockerignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Git files
2+
.git
3+
.gitignore
4+
.gitattributes
5+
6+
# Build results
7+
[Bb]in/
8+
[Oo]bj/
9+
[Dd]ebug/
10+
[Rr]elease/
11+
x64/
12+
x86/
13+
build/
14+
bld/
15+
[Ll]og/
16+
17+
# User-specific files
18+
*.user
19+
*.userosscache
20+
*.suo
21+
*.userprefs
22+
*.vs
23+
24+
# Test results
25+
TestResults/
26+
coverage/
27+
28+
# Docker files (for clean recursive builds)
29+
Dockerfile
30+
.dockerignore
31+
32+
# NuGet packages
33+
*.nupkg
34+
*.snupkg
35+
**/packages/*
36+
!**/packages/build/
37+
38+
# Temp files
39+
.DS_Store
40+
Thumbs.db
41+
*.tmp
42+
*~
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
tag:
9+
description: 'Docker tag (default: latest)'
10+
required: false
11+
default: 'latest'
12+
13+
jobs:
14+
build-and-push:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v3
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v2
26+
27+
- name: Log in to the Container registry
28+
uses: docker/login-action@v2
29+
with:
30+
registry: ghcr.io
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Extract metadata (tags, labels) for Docker
35+
id: meta
36+
uses: docker/metadata-action@v4
37+
with:
38+
images: ghcr.io/${{ github.repository }}
39+
tags: |
40+
type=ref,event=branch
41+
type=ref,event=pr
42+
type=semver,pattern={{version}}
43+
type=semver,pattern={{major}}.{{minor}}
44+
${{ github.event.inputs.tag || 'latest' }}
45+
46+
- name: Build and push Docker image
47+
uses: docker/build-push-action@v4
48+
with:
49+
context: .
50+
push: true
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
cache-from: type=gha
54+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Build stage
2+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
3+
WORKDIR /src
4+
5+
# Copy solution file and project files
6+
COPY ["CosmosDbDataMigrationTool.sln", "."]
7+
COPY ["Directory.Packages.props", "."]
8+
COPY ["Core/", "Core/"]
9+
COPY ["Interfaces/", "Interfaces/"]
10+
COPY ["Extensions/", "Extensions/"]
11+
12+
# Restore dependencies
13+
# Increase the timeout and number of retries for NuGet
14+
RUN dotnet nuget list source | grep -q 'nuget.org' || dotnet nuget add source https://api.nuget.org/v3/index.json --name nuget.org
15+
ENV NUGET_PACKAGES=/nuget-packages
16+
ENV NUGET_HTTP_CACHE_PATH=/nuget-http-cache
17+
RUN mkdir -p /nuget-packages /nuget-http-cache
18+
19+
# Restore and build the main project and the core project
20+
RUN dotnet restore "Core/Cosmos.DataTransfer.Core/Cosmos.DataTransfer.Core.csproj" --disable-parallel
21+
RUN dotnet build "Core/Cosmos.DataTransfer.Core/Cosmos.DataTransfer.Core.csproj" -c Release -o /app/build/Core --no-restore
22+
RUN dotnet publish "Core/Cosmos.DataTransfer.Core/Cosmos.DataTransfer.Core.csproj" -c Release -o /app/publish/Core --no-restore
23+
24+
# Build and publish ALL extensions
25+
RUN find Extensions -name "*.csproj" | grep -v "UnitTests" | xargs -I {} sh -c 'dotnet publish "{}" -c Release -o /app/publish/Core/Extensions || echo "Skipping $(basename $(dirname {}))"'
26+
27+
# Runtime stage
28+
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS runtime
29+
WORKDIR /app
30+
31+
# Copy published files from build stage
32+
COPY --from=build /app/publish/Core ./
33+
34+
# Create volumes for configuration and data
35+
VOLUME /config
36+
VOLUME /data
37+
38+
# Optional volume for custom extensions
39+
VOLUME /extensions
40+
41+
# Set the entrypoint
42+
ENTRYPOINT ["dotnet", "dmt.dll"]

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,56 @@ The Azure Cosmos DB Desktop Data Migration Tool is an open-source project contai
2626

2727
## Quick Installation
2828

29-
To use the tool, download the latest archive file for your platform (win-x64, win-arm64, mac-x64, mac-arm64, linux-x64, linux-arm64) from [Releases](https://github.com/AzureCosmosDB/data-migration-desktop-tool/releases) and extract all files to your desired install location. To begin a data transfer operation, first populate the `migrationsettings.json` file with appropriate settings for your data source and sink (see [detailed instructions](#using-the-command-line) below or [review examples](ExampleConfigs.md)), and then run the application from a command line: `dmt.exe` on Windows or `dmt` on other platforms.
29+
To use the tool, download the latest archive file for your platform (win-x64, win-arm64, mac-x64, mac-arm64, linux-x64, linux-arm64) from [Releases](https://github.com/AzureCosmosDB/data-migration-desktop-tool/releases) and extract all files to your desired install location. To begin a data transfer operation, first populate the `migrationsettings.json` file with appropriate settings for your data source and sink (see [detailed instructions](#using-the-command-line) below or [review examples](ExampleConfigs.md)), and then run the application from a command line: `dmt.exe` on Windows or `dmt` on other platforms.
30+
31+
## Docker Container
32+
33+
You can also run the Data Migration Tool as a Docker container, which is useful for CI/CD pipelines or environments where installing the tool directly isn't preferred.
34+
35+
### Using Pre-built Docker Image
36+
37+
The easiest way to use the container is to pull the pre-built image from GitHub Container Registry:
38+
39+
```bash
40+
docker pull ghcr.io/azurecosmosdb/data-migration-desktop-tool:latest
41+
docker run -v $(pwd)/config:/config -v $(pwd)/data:/data ghcr.io/azurecosmosdb/data-migration-desktop-tool:latest run --settings /config/migrationsettings.json
42+
```
43+
44+
### Building the Docker Image Locally
45+
46+
To build the Docker image locally:
47+
48+
```bash
49+
docker build -t data-migration-tool .
50+
```
51+
52+
### Running the Container
53+
54+
Run the container with your configuration files mounted:
55+
56+
```bash
57+
docker run -v $(pwd)/config:/config -v $(pwd)/data:/data data-migration-tool run --settings /config/migrationsettings.json
58+
```
59+
60+
Where:
61+
- `/config` contains your configuration files including `migrationsettings.json`
62+
- `/data` is the directory for your data files
63+
64+
You can also mount custom extensions:
65+
66+
```bash
67+
docker run -v $(pwd)/config:/config -v $(pwd)/data:/data -v $(pwd)/extensions:/extensions data-migration-tool run --source customsource --sink customsink --settings /config/migrationsettings.json
68+
```
69+
70+
### Docker Compose Example
71+
72+
A `docker-compose.yml` file is provided as an example:
73+
74+
```bash
75+
docker-compose up
76+
```
77+
78+
This will build the image and run the container with the mounted volumes. You can modify the `docker-compose.yml` file to customize the command and volumes.
3079

3180
### Special Extensions
3281

config/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore all files in this directory
2+
*
3+
# Except this file
4+
!.gitignore

data/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ignore all files in this directory
2+
*
3+
# Except this file
4+
!.gitignore
5+
# And except the sample file
6+
!sample-data.json

data/sample-data.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"id": "1",
4+
"name": "Sample Item 1",
5+
"description": "This is a sample item for testing the data migration tool"
6+
},
7+
{
8+
"id": "2",
9+
"name": "Sample Item 2",
10+
"description": "This is another sample item"
11+
}
12+
]

docker-compose.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: '3'
2+
3+
services:
4+
data-migration-tool:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
volumes:
9+
# Mount configuration files from the host
10+
- ./config:/config
11+
# Mount data files for import/export
12+
- ./data:/data
13+
# Example command (customize based on your needs)
14+
# The default entrypoint is "dotnet dmt.dll"
15+
command: run --settings /config/migrationsettings.json
16+
# Uncomment these environment variables to use RBAC authentication
17+
# environment:
18+
# - AZURE_TENANT_ID=your-tenant-id
19+
# - AZURE_CLIENT_ID=your-client-id
20+
# - AZURE_CLIENT_SECRET=your-client-secret

0 commit comments

Comments
 (0)