From 066c15e97643a613a31780b01e38a7123a3fd5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Mon, 18 Mar 2024 17:01:53 -0400 Subject: [PATCH] Add Dockerfile and Makefile for oohelperd --- oonith/Dockerfile | 27 +++++++++++++++++++++ oonith/Makefile | 58 ++++++++++++++++++++++++++++++++++++++++++++ oonith/buildspec.yml | 29 ++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 oonith/Dockerfile create mode 100644 oonith/Makefile create mode 100644 oonith/buildspec.yml diff --git a/oonith/Dockerfile b/oonith/Dockerfile new file mode 100644 index 00000000..6b60b41c --- /dev/null +++ b/oonith/Dockerfile @@ -0,0 +1,27 @@ +FROM golang:1.20.12-bullseye as builder +ARG BRANCH_NAME=master + +WORKDIR /build + +RUN echo "cloning $BRANCH_NAME" && git clone --branch $BRANCH_NAME https://github.com/ooni/probe-cli + +WORKDIR /build/probe-cli + +RUN go run ./internal/cmd/buildtool oohelperd build + +## Image running on the host +FROM golang:1.20.12-bullseye as runner + +WORKDIR /app + +COPY --from=builder /build/probe-cli/CLI/oohelperd-* /app +RUN mv oohelperd-* oohelperd + +# oohelperd service +EXPOSE 8080 + +# prometheus metrics +EXPOSE 9091 + +# Run +CMD ["/app/oohelperd", "-api-endpoint", "0.0.0.0:8080", "--prometheus-endpoint", "0.0.0.0:9091"] diff --git a/oonith/Makefile b/oonith/Makefile new file mode 100644 index 00000000..e43e589b --- /dev/null +++ b/oonith/Makefile @@ -0,0 +1,58 @@ +SERVICE_NAME ?= oohelperd + +ECS_CONTAINER_NAME ?= oonith-service-$(SERVICE_NAME) +IMAGE_NAME ?= ooni/oonith-$(SERVICE_NAME) +DATE := $(shell python3 -c "import datetime;print(datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%d'))") +GIT_FULL_SHA ?= $(shell git rev-parse HEAD) +SHORT_SHA := $(shell echo ${GIT_FULL_SHA} | cut -c1-8) +PKG_VERSION := "3.20.1" + +BUILD_LABEL := $(DATE)-$(SHORT_SHA) +VERSION_LABEL = v$(PKG_VERSION) +ENV_LABEL ?= latest + +print-labels: + echo "ECS_CONTAINER_NAME=${ECS_CONTAINER_NAME}" + echo "PKG_VERSION=${PKG_VERSION}" + echo "BUILD_LABEL=${BUILD_LABEL}" + echo "VERSION_LABEL=${VERSION_LABEL}" + echo "ENV_LABEL=${ENV_LABEL}" + +docker-build: + # We need to use tar -czh to resolve the common dir symlink + tar -czh . | docker build \ + --build-arg BRANCH_NAME=${VERSION_LABEL} \ + -t ${IMAGE_NAME}:${BUILD_LABEL} \ + -t ${IMAGE_NAME}:${VERSION_LABEL} \ + -t ${IMAGE_NAME}:${ENV_LABEL} \ + - + echo "built image: ${IMAGE_NAME}:${BUILD_LABEL} (${IMAGE_NAME}:${VERSION_LABEL} ${IMAGE_NAME}:${ENV_LABEL})" + +docker-push: + # We need to use tar -czh to resolve the common dir symlink + docker push ${IMAGE_NAME}:${BUILD_LABEL} + docker push ${IMAGE_NAME}:${VERSION_LABEL} + docker push ${IMAGE_NAME}:${ENV_LABEL} + +docker-smoketest: + echo "no smoketest implemented" + +imagedefinitions.json: + echo '[{"name":"${ECS_CONTAINER_NAME}","imageUri":"${IMAGE_NAME}:${BUILD_LABEL}"}]' > imagedefinitions.json + +test: + hatch run test + +test-cov: + hatch run test-cov + +build: + echo "no build implemented" + +clean: + rm -f imagedefinitions.json + +run: + echo "no run implemented" + +.PHONY: init test build clean docker print-labels diff --git a/oonith/buildspec.yml b/oonith/buildspec.yml new file mode 100644 index 00000000..55faa562 --- /dev/null +++ b/oonith/buildspec.yml @@ -0,0 +1,29 @@ +version: 0.2 +env: + variables: + OONI_CODE_PATH: oonith + DOCKERHUB_SECRET_ID: oonidevops/dockerhub/access_token + +phases: + install: + runtime-versions: + python: 3.11 + + pre_build: + commands: + - echo "Logging in to dockerhub" + - DOCKER_SECRET=$(aws secretsmanager get-secret-value --secret-id $DOCKERHUB_SECRET_ID --query SecretString --output text) + - echo $DOCKER_SECRET | docker login --username ooni --password-stdin + + build: + commands: + - export GIT_FULL_SHA=${CODEBUILD_RESOLVED_SOURCE_VERSION} + - cd $OONI_CODE_PATH + - make docker-build + - make docker-smoketest + - make docker-push + - make imagedefinitions.json + - cat imagedefinitions.json | tee ${CODEBUILD_SRC_DIR}/imagedefinitions.json + +artifacts: + files: imagedefinitions.json