Skip to content

Commit

Permalink
Merge pull request #10 from userver-framework/feature/24.04
Browse files Browse the repository at this point in the history
feat ci: up to 24.04 docker image
  • Loading branch information
segoon authored Feb 11, 2025
2 parents 448ad37 + ed4dd8e commit 9ae3456
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 124 deletions.
28 changes: 2 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
- os: ubuntu-24.04
make: test-debug
info: g++-11 + test-debug

- os: ubuntu-22.04
- os: ubuntu-24.04
make: test-release
info: g++-11 + test-release

Expand Down Expand Up @@ -66,27 +66,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
17 changes: 2 additions & 15 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,11 @@ 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

- name: Build
run: make docker-build-release

- name: Run tests
run: |
docker-compose run --entrypoint="" --rm service_template-container bash -c '
apt update
apt install -y mongodb-org mongodb-mongosh
./tests/run_as_user.sh make test-release
'
- name: Test
run: make docker-test-release
35 changes: 15 additions & 20 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/service_template \
--config /home/user/.local/etc/service_template/static_config.yaml \
--config_vars /home/user/.local/etc/service_template/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 -p 8081:8081 --rm service_template-container make -- --in-docker-start-$*

# Start specific target in docker environment
# 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-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
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 $*
45 changes: 0 additions & 45 deletions docker-compose.yml

This file was deleted.

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 9ae3456

Please sign in to comment.