From 25a3fbb5d3de389e8ae092967b99bdc777136754 Mon Sep 17 00:00:00 2001 From: Andy Malakov Date: Thu, 19 Jun 2025 09:06:31 -0400 Subject: [PATCH] Adding CI --- .github/workflows/docker-build.yml | 34 ++++++++++++++++++++ .github/workflows/docker-publish.yml | 47 ++++++++++++++++++++++++++++ README.md | 28 +++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 .github/workflows/docker-build.yml create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..bd84da6 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,34 @@ +name: Build Docker Container + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: false + tags: java-profiler-tools:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Test Docker image + run: | + docker run --rm java-profiler-tools:latest java -version + docker run --rm java-profiler-tools:latest ls -la /usr/local/async-profiler/ + docker run --rm java-profiler-tools:latest ls -la /usr/local/flame-graph/ \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..42beb3e --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,47 @@ +name: Publish Docker Image + +on: + push: + branches: [ main, master ] + tags: [ 'v*' ] + workflow_dispatch: + +jobs: + publish: + runs-on: ubuntu-latest + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ secrets.DOCKER_USERNAME }}/java-profiler-tools + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/README.md b/README.md index 94b00eb..85a3a1f 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,31 @@ This container can be handy when you need to attach to some Java container and Usage example can be found [here](https://ember.deltixlab.com/docs/kb/profiling/?_highlight=perf#profiling-ember-with-perf). +## CI/CD + +This project uses GitHub Actions for continuous integration and deployment: + +### Build Workflow +- **File**: `.github/workflows/docker-build.yml` +- **Triggers**: Push to main/master branch, pull requests, manual dispatch +- **Actions**: Builds the Docker image and runs basic tests +- **No external dependencies required** + +### Publish Workflow (Optional) +- **File**: `.github/workflows/docker-publish.yml` +- **Triggers**: Push tags starting with 'v' (e.g., v1.0.0), manual dispatch +- **Actions**: Builds and publishes the Docker image to Docker Hub +- **Required secrets**: `DOCKER_USERNAME` and `DOCKER_PASSWORD` + +### Setting up Docker Hub Publishing +If you want to publish to Docker Hub, add these secrets to your GitHub repository: +1. Go to your repository Settings → Secrets and variables → Actions +2. Add `DOCKER_USERNAME` with your Docker Hub username +3. Add `DOCKER_PASSWORD` with your Docker Hub access token + +Then create a tag to trigger the publish workflow: +```bash +git tag v1.0.0 +git push origin v1.0.0 +``` +