Skip to content

Commit

Permalink
feat ci: up to 24.04 docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
segoon committed Feb 11, 2025
1 parent 99f3234 commit 1e9c9b1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 72 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 17 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 $*
13 changes: 13 additions & 0 deletions run_as_user.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
18 changes: 0 additions & 18 deletions tests/run_as_user.sh

This file was deleted.

0 comments on commit 1e9c9b1

Please sign in to comment.