diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b29dee..005e9e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,27 +57,3 @@ jobs: - name: Run ${{matrix.make}} run: | make ${{matrix.make}} - - - name: Test install ${{matrix.make}} - if: matrix.make == 'test-release' - run: | - make dist-clean - make install PREFIX=`pwd`/local_installation/ - - - name: Test run after install - if: matrix.make == 'test-release' - run: >- - ./local_installation/bin/service_template - --config=./local_installation/etc/service_template/static_config.yaml - --config_vars=./local_installation/etc/service_template/config_vars.yaml - & - - - name: Check work run service - if: matrix.make == 'test-release' - run: | - ps aux | grep service_template | grep config && curl http://localhost:8080/ping -v - - - name: Stop all - if: matrix.make == 'test-release' - run: | - killall service_template diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 8dc1e9a..544904c 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -27,14 +27,6 @@ jobs: ccache-dir-${{github.ref}}_run- ccache- - - name: Install docker-compose - run: | - sudo apt update - sudo apt install --allow-downgrades -y docker-compose - - - name: Setup ccache - run: docker-compose run --rm service_template-container bash -c 'ccache -M 2.0GB && ccache -s' - - name: Cmake run: make docker-cmake-release diff --git a/Makefile b/Makefile index cdaa300..f3138c2 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ PROJECT_NAME = service_template NPROCS ?= $(shell nproc) CLANG_FORMAT ?= clang-format -DOCKER_COMPOSE ?= docker-compose +DOCKER_IMAGE ?= ghcr.io/userver-framework/ubuntu-24.04-userver:latest +# If we're under TTY, pass "-it" to "docker run" +DOCKER_ARGS = $(shell /bin/test -t 0 && /bin/echo -it || echo) PRESETS ?= debug release debug-custom release-custom .PHONY: all @@ -60,24 +62,17 @@ format: find src -name '*pp' -type f | xargs $(CLANG_FORMAT) -i find tests -name '*.py' -type f | xargs autopep8 -i -# Internal hidden targets that are used only in docker environment -.PHONY: $(addprefix --in-docker-start-, $(PRESETS)) -$(addprefix --in-docker-start-, $(PRESETS)): --in-docker-start-%: install-% - /home/user/.local/bin/$(PROJECT_NAME) \ - --config /home/user/.local/etc/$(PROJECT_NAME)/static_config.yaml \ - --config_vars /home/user/.local/etc/$(PROJECT_NAME)/config_vars.yaml - -# Build and run service in docker environment -.PHONY: $(addprefix docker-start-, $(PRESETS)) -$(addprefix docker-start-, $(PRESETS)): docker-start-%: - $(DOCKER_COMPOSE) run -p 8080:8080 --rm $(PROJECT_NAME)-container make -- --in-docker-start-$* - -# Start specific target in docker environment -.PHONY: $(addprefix docker-cmake-, $(PRESETS)) $(addprefix docker-build-, $(PRESETS)) $(addprefix docker-test-, $(PRESETS)) $(addprefix docker-clean-, $(PRESETS)) $(addprefix docker-install-, $(PRESETS)) -$(addprefix docker-cmake-, $(PRESETS)) $(addprefix docker-build-, $(PRESETS)) $(addprefix docker-test-, $(PRESETS)) $(addprefix docker-clean-, $(PRESETS)) $(addprefix docker-install-, $(PRESETS)): docker-%: - $(DOCKER_COMPOSE) run --rm $(PROJECT_NAME)-container make $* - -# Stop docker container and cleanup data -.PHONY: docker-clean-data -docker-clean-data: - $(DOCKER_COMPOSE) down -v +# Start targets makefile in docker wrapper. +# The docker mounts the whole service's source directory, +# so you can do some stuff as you wish, switch back to host (non-docker) system +# and still able to access the results. +.PHONY: $(addprefix docker-cmake-, $(PRESETS)) $(addprefix docker-build-, $(PRESETS)) $(addprefix docker-test-, $(PRESETS)) $(addprefix docker-clean-, $(PRESETS)) +$(addprefix docker-cmake-, $(PRESETS)) $(addprefix docker-build-, $(PRESETS)) $(addprefix docker-test-, $(PRESETS)) $(addprefix docker-clean-, $(PRESETS)): docker-%: + docker run $(DOCKER_ARGS) \ + --network=host \ + -v $$PWD:$$PWD \ + -w $$PWD \ + $(DOCKER_IMAGE) \ + env CCACHE_DIR=$$PWD/.ccache \ + HOME=$$HOME \ + $$PWD/run_as_user.sh $(shell /bin/id -u) $(shell /bin/id -g) make $* diff --git a/run_as_user.sh b/run_as_user.sh new file mode 100755 index 0000000..25e78b1 --- /dev/null +++ b/run_as_user.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Exit on any error and treat unset variables as errors +set -euo + +OLD_UID=$1 +OLD_GID=$2 +shift; shift + +groupadd --gid $OLD_GID --non-unique user +useradd --uid $OLD_UID --gid $OLD_GID --non-unique user + +sudo -E -u user "$@" diff --git a/tests/run_as_user.sh b/tests/run_as_user.sh deleted file mode 100755 index 5e0c9f1..0000000 --- a/tests/run_as_user.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -# Exit on any error and treat unset variables as errors -set -euo pipefail - -DIR_UID="$(stat -c '%u' .)" - -if ! id -u user > /dev/null 2> /dev/null; then - if [ "$DIR_UID" = "0" ]; then - useradd --create-home --no-user-group user - else - useradd --create-home --no-user-group --uid $DIR_UID user - fi -elif [ "$DIR_UID" != "0" ]; then - usermod -u $DIR_UID user -fi - -HOME=/home/user sudo -E -u user "$@"