Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: push base image to DockerHub #50

Merged
merged 13 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "../Dockerfile"
"dockerfile": "../docker/lf.Dockerfile"
},

// Arguments:
Expand Down
54 changes: 0 additions & 54 deletions .github/workflows/ci-docker.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Nightly CI
name: CI - Nightly

on:
release:
Expand All @@ -12,6 +12,7 @@ env:

jobs:

# This job checks if the main branch has changed in the last 24 hours
check_change:
runs-on: ubuntu-latest
name: Check latest commit
Expand All @@ -28,6 +29,8 @@ jobs:
if: ${{ github.event_name == 'schedule' }}
run: test -z $(git rev-list --after="24 hours" ${{ github.sha }}) && echo "::set-output name=main_changed::false"

# This job builds the project and runs the tests. Because building the project
# is time-consuming, we only run this job nightly.
build:
needs: check_change
if: ${{ needs.check_change.outputs.main_changed != 'false' }}
Expand All @@ -51,3 +54,21 @@ jobs:
- name: Test
# Execute tests defined by the CMake configuration.
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target run_tests

# This job runs the devcontainer/ci action to build and run the dev container
# and execute the tests in the container. Because building the container is
# time-consuming, we only run this job nightly.
docker_dev:
needs: check_change
if: ${{ needs.check_change.outputs.main_changed != 'false' }}

runs-on: ubuntu-latest
steps:

- name: Checkout (GitHub)
uses: actions/checkout@v4

- name: Build and run dev container task
uses: devcontainers/[email protected]
with:
runCmd: ./tests.sh
32 changes: 32 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI - Build and Tests

on:
push:
branches: ["open-source"]
pull_request:
branches: ["open-source"]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
docker-test:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
- name: Start dev container
run: cd docker && ./docker.sh dev_create && ./docker.sh dev_up
- name: Run tests in dev container
run: cd docker && ./docker.sh dev_exec ls -al lightning-filter && ./docker.sh dev_exec bash lightning-filter/tests.sh
- name: Upload artifacts
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: tests-artifacts
path: tmp/tests_artifacts
- name: Clear artifacts
run: rm -rf tmp/tests_artifacts
- name: Stop dev container
run: cd docker && ./docker.sh dev_down
95 changes: 0 additions & 95 deletions docker.sh

This file was deleted.

63 changes: 63 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Makefile for building docker images and pushing them to Docker Hub.
# When pushing to Docker Hub, you must be logged in:
# docker login -u $(DOCKER_REGISTRY)
#
# When pulling from Docker Hub, the SHA256 digest uniquely identifies the image.
#
# To change the an image:
# 1. Update the Dockerfile as you like.
# 2. Run `make build-<image>` to build the image.
# 3. Run `make push-<image>` to push the image to Docker Hub.
# 4. Run `make update-<image>-digest` to store the SHA256 digest of the image.

# Docker Hub variables
DOCKER_REGISTRY = streun
DOCKER_IMAGE_NAME = lightning-filter

# With DPDK_MINIMAL_BUILD set to true, DPDK is build without host machine optimization, e.g., SSE2,
# providing better compatibility with different systems (useful for CI pipelines).
DPDK_MINIMAL_BUILD = true

.PHONY: all
all: build-base-image update-digest

# Base image
TAG_BASE = $(shell cat base.version)
build-base-image:
@echo "Building $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_BASE)"
docker build --target lf-base -t $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_BASE) \
--build-arg DPDK_MINIMAL_BUILD=$(DPDK_MINIMAL_BUILD) \
-f base.Dockerfile .

pull-base-image:
@echo "Pulling $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME) by SHA256 digest"
docker pull $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_BASE)@$(shell cat base.digest)

push-base-image:
@echo "Pushing $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_BASE) to Docker Hub."
docker push $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_BASE)

update-base-digest:
@echo "Storing SHA256 digest of $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME)"
docker inspect --format='{{index .RepoDigests 0}}' $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_BASE) | cut -d '@' -f 2 > base.digest

# Development image
TAG_DEV = $(shell cat dev.version)
build-dev-image:
@echo "Building $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_DEV)"
docker build --target lf-dev -t $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_DEV) \
--build-arg DPDK_MINIMAL_BUILD=$(DPDK_MINIMAL_BUILD) \
-f base.Dockerfile .

pull-dev-image:
@echo "Pulling $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_DEV) by SHA256 digest"
docker pull $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_DEV)@$(shell cat dev.digest)
docker tag $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_DEV) lf-dev:latest

push-dev-image:
@echo "Pushing $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_DEV) to Docker Hub."
docker push $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_DEV)

update-dev-digest:
@echo "Storing SHA256 digest of $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_DEV)"
docker inspect --format='{{index .RepoDigests 0}}' $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(TAG_DEV) | cut -d '@' -f 2 > dev.digest
10 changes: 10 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Docker Images

This directory contains the Dockerfiles for the images used in the project.
The goal is to have a simple and easy way to build, run, develop, and test the lightning filter.

There are two images: `base` and `dev`.
The base image contains the necessary dependencies to build the lightning filter,
such as DPDK.
The dev image is based on the base image but also includes tools for development and testing.
The dev image is used to test the lightning filter in the CI pipeline.
1 change: 1 addition & 0 deletions docker/base.digest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sha256:46b4deca246211865ba0870d792a32337e28d5c704b89606eb8bcbf2610e851c
1 change: 1 addition & 0 deletions docker/base.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lf-base-v0.1.0
1 change: 1 addition & 0 deletions docker/dev.digest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sha256:92445ec8907ca98871fb2f2ceae1898e5bbb0106c61cfc98481473624a5ab1d3
1 change: 1 addition & 0 deletions docker/dev.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lf-dev-v0.1.0
49 changes: 49 additions & 0 deletions docker/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

set -x

# directory of this script
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
# base directory of the project
base_dir=$script_dir/..

cmd_dev_create() {
DEV_VERSION=$(cat dev.version)
docker create --name lf-dev-container --privileged --net=host \
-v $base_dir:/home/lf/lightning-filter/ \
-v /dev/hugepages:/dev/hugepages -v /sys/bus/pci/devices:/sys/bus/pci/devices \
streun/lightning-filter:$DEV_VERSION sleep infinity
}

cmd_dev_up() {
docker start lf-dev-container
}

cmd_dev_down() {
docker stop lf-dev-container
}

cmd_dev_exec() {
docker exec lf-dev-container "$@"
}

cmd_help() {
echo
cat <<-_EOF
Usage:
$PROGRAM help
Show this text.
_EOF
}

# END subcommand functions

PROGRAM="${0##*/}"
COMMAND="$1"
shift

case "$COMMAND" in
help|dev_image|dev_create|dev_up|dev_down|dev_exec)
"cmd_$COMMAND" "$@" ;;
*) cmd_help; exit 1 ;;
esac
Loading