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

Add Dockerfile and buildspec for oohelperd #827

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 27 additions & 0 deletions oonith/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
58 changes: 58 additions & 0 deletions oonith/Makefile
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions oonith/buildspec.yml
Original file line number Diff line number Diff line change
@@ -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
Loading