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

✨Run dynamic services via dynamic-sidecar (🏗️ OPS + CI action) #1887

Merged
merged 794 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
794 commits
Select commit Hold shift + click to select a range
e8cbdf7
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jun 16, 2021
0e164bd
codestyle
Jun 16, 2021
d738812
updated openapi.json
Jun 16, 2021
415a2b5
fixed failing tests
Jun 16, 2021
597760d
added defaults for registry in development
Jun 16, 2021
33b1235
fixed models-library failing tests
Jun 16, 2021
02ea877
fixing pylint
Jun 16, 2021
0801c2b
added back missing
Jun 16, 2021
f40d9e6
fix pylint
Jun 16, 2021
f3ecd9d
containe-http-entrypoint requires compose-spec
Jun 16, 2021
055d1ca
fixed test which was causing all others to fail
Jun 16, 2021
24d49fc
removed fixture for network_name
Jun 16, 2021
8c0c6d6
changed application setup
Jun 16, 2021
2b881f2
added mocked swarm network
Jun 16, 2021
db976e8
fix codeclimate
Jun 16, 2021
1e017d2
fixed weberrver integration 06 and 09 tests
Jun 16, 2021
be3a845
fixed webserver integration 10 tests
Jun 16, 2021
23c37f2
fix failing unit tests
Jun 17, 2021
3b6abde
codeclimate will not fix
Jun 17, 2021
61fee20
monitor needs to be shutdown while not in swarm mode
Jun 17, 2021
6ea2390
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jun 17, 2021
71fc4bc
fixing timeouts for the CI
Jun 17, 2021
7b666dd
removed adminer
Jun 17, 2021
58008eb
CI can be a pain, give it a lot of time
Jun 17, 2021
34e4c06
updated specs
Jun 17, 2021
437a4eb
removed otudated TODO
Jun 17, 2021
32a6cb4
refactored, to using model instead of properties
Jun 17, 2021
9a3a66e
unmeaningful comment
Jun 17, 2021
f1e729e
fixed type
Jun 17, 2021
24dabee
added more hints for developers
Jun 17, 2021
a2a83af
removed undesired log
Jun 18, 2021
13256f5
fixed errors after refactor
Jun 18, 2021
5c098e1
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jun 18, 2021
4c8da7b
fixed makefile syntax
Jun 18, 2021
24fa540
displaying message in terminal
Jun 18, 2021
c63e988
updated comment and now raising error if fails
Jun 18, 2021
88db016
Update test_service_settings.py
pcrespov Jun 21, 2021
5a3a0a1
@sanderegg typo fix
Jun 21, 2021
df834ae
@sanderegg fixed type
Jun 21, 2021
3f4fd6c
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jun 22, 2021
0795609
added missing commits to previous merge
Jun 22, 2021
480e9ab
Merge branch 'adding-service-sidecar' of github.com:GitHK/osparc-simc…
Jun 22, 2021
060ac3b
director-v2 codestyle
Jun 22, 2021
f348bae
added missing dependencies
Jun 22, 2021
d41a07a
updated pyton version in worfklow
Jun 22, 2021
3038268
added missing dependency
Jun 23, 2021
27134bb
updated types and fixed deserialization
Jun 23, 2021
74f6e36
updated types
Jun 23, 2021
b5f085e
renamed service_settings entries
Jun 23, 2021
7758b5d
renamed modes related to the service settings
Jun 24, 2021
04e2198
fixing output
Jun 24, 2021
cee3af1
renamed and semplified constructors
Jun 24, 2021
a4bd47a
node_uuid type is now NodeID
Jun 24, 2021
3b7ce38
removed unsued
Jun 24, 2021
64d8e09
fixed regex
Jun 24, 2021
1670688
reanbled and fixed tests
Jun 24, 2021
7d6ca83
changed :labels to /labels
Jun 24, 2021
874874e
renamed other_paths to state_paths
Jun 24, 2021
298f9be
expanded example
Jun 24, 2021
9e08bfc
fixed imports and types
Jun 24, 2021
f0ba7a6
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jun 24, 2021
e73ad69
test required to be in swarm mode
Jun 25, 2021
d6cf62c
doubling the time for the CI
Jun 25, 2021
8172573
refactor naming
Jun 25, 2021
e9b02e6
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jun 25, 2021
b206f9f
refactored RegistrySettings to new standard
Jun 25, 2021
3f6c8d2
refactored test
Jun 25, 2021
587cb21
more registry refactor
Jun 25, 2021
2ccf99e
removed unused definitions and RunningDynamicServiceDetails to avoid …
Jun 25, 2021
10676d0
refactored to semplify filtering
Jun 25, 2021
05f9755
refactor, added constructor moved model
Jun 25, 2021
88770e8
updated comments
Jun 25, 2021
6ac01cb
added constructor to model
Jun 25, 2021
f5960f7
removed comments
Jun 25, 2021
308b2e3
renamed moitor.core to monitor.monitor.task
Jun 25, 2021
db9efd9
simplifyng imports
Jun 25, 2021
4b348a6
moved gt_moinitor to dependencies
Jun 25, 2021
7824d48
removed TODO and expanded comment
Jun 25, 2021
dcfd57c
simplified status reported to the user
Jun 25, 2021
98b1d81
fixed dynamic-sidcar stuck boot
Jun 25, 2021
6bf4082
fixed type order
Jun 28, 2021
12797aa
adding missing optional
Jun 28, 2021
62f974d
- moved needs_dynamic_sidecar to property
Jun 28, 2021
e514eb1
refactored factory method
Jun 28, 2021
ef03808
moved hardcoded traefik version to DynamicSidecarSettings
Jun 28, 2021
7e8ceb3
refactored list_running_dynamic_services
Jun 28, 2021
7ec64a4
update docstring
Jun 28, 2021
330cced
will no longer suppress but display a warning
Jun 28, 2021
dadacbe
moved where the function is used
Jun 28, 2021
b109130
renamed properly
Jun 28, 2021
fffae11
renamed OverallStatus to Status
Jun 28, 2021
9f40a4d
refactored make_from_http_request
Jun 28, 2021
6175d84
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jun 28, 2021
e86f5da
refactored settings to new pattern and cleanup
Jun 29, 2021
bfaba5d
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jun 29, 2021
47540c3
pylint
Jun 29, 2021
ae369ff
updated openapi-specs
Jun 29, 2021
b95a575
renamed to module_setup
Jun 29, 2021
90933b9
renamed to docker_api
Jun 29, 2021
fa5b574
renamed to client_api interface and refactored interface
Jun 29, 2021
683d736
renamed to docker_compose_specs
Jun 29, 2021
e8c7210
renamed to docker_service_specs
Jun 29, 2021
db38cb5
renamed to docker_states
Jun 29, 2021
f32fa01
renaming to errors
Jun 29, 2021
48b2226
renaming to errors part 2
Jun 29, 2021
742b994
renamed events
Jun 29, 2021
cc2ba3b
renamed to abc and inherited from ABC
Jun 29, 2021
f3309ce
renaming to task
Jun 29, 2021
7845b7d
renamed task part 2
Jun 29, 2021
b61755c
refactor @pcrespov
Jun 29, 2021
c7fb8f1
refactor
Jun 29, 2021
00bca39
review @pcrespov
Jun 29, 2021
0f8941f
review @crespov
Jun 29, 2021
67a0341
typing error
Jun 29, 2021
34e821f
fixed typing
Jun 29, 2021
12675c0
using py3.8 syntax
Jun 29, 2021
d5e6ebe
pylance improovment
Jun 29, 2021
571b6e1
py3.8 syntax
Jun 29, 2021
7922116
@crespov refactor
Jun 29, 2021
0d1b89c
pylance suggestions
Jun 29, 2021
0b45d9f
more pylance suggestions
Jun 29, 2021
5a093e7
making pylance happy
Jun 29, 2021
2ec90c8
minor pylance suggsestions
Jun 29, 2021
d93345b
using a valid status
Jun 29, 2021
57b01d1
refactored to Pydantic model and moved to models
Jun 29, 2021
1069053
removed make from name
Jun 29, 2021
c30b357
removed unecessary code
Jun 29, 2021
02ed118
fixed constructor
Jun 29, 2021
3c290d6
models restructured:
Jun 29, 2021
b287fed
removed unncessary
Jun 29, 2021
925f843
pylance suggestion
Jun 29, 2021
e64a550
py38 syntax
Jun 29, 2021
c9d8f26
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jun 29, 2021
e970669
remove unsued import
Jun 30, 2021
6d07fd2
removed unused code
Jun 30, 2021
c1b5e0c
added test for fetched labesl and refactored
Jun 30, 2021
0c43f39
fixed module setup
Jun 30, 2021
9a46f0c
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jun 30, 2021
5166cfc
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jun 30, 2021
80c8bcc
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jul 1, 2021
7a49ba8
inverted parameter order
Jul 9, 2021
983e3b7
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jul 26, 2021
55f05ec
added missing changes
Jul 26, 2021
e84c9ec
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jul 26, 2021
3df966a
fixing workflow
Jul 26, 2021
8501db4
fixes issues with imagename
Jul 26, 2021
ef77717
switching to default
Jul 26, 2021
b8272ac
refactored
Jul 26, 2021
0bddb46
reverted test
Jul 26, 2021
431db00
trying to debug
Jul 26, 2021
62b5695
fixed validator for CI
Jul 26, 2021
0742220
added todo before merging
Jul 26, 2021
1ab0c2b
downgrading dependency which causes issues
Jul 26, 2021
33e094f
pylint
Jul 26, 2021
0050d36
updated name in CI
Jul 26, 2021
8d972d5
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jul 28, 2021
2983cb2
fixes failing fixture
Jul 28, 2021
20e002c
typing
Jul 28, 2021
618905a
bumping timeout to avoid test failing
Jul 28, 2021
fa76f65
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jul 28, 2021
909c6f2
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jul 29, 2021
06fadd3
refactor
Jul 29, 2021
5c3ba10
renamed back to original name
Jul 29, 2021
fb29bfe
moved traefik settings to env vars and pydantic models
Jul 29, 2021
7934cc3
- refactor function names
Jul 29, 2021
054ee9b
codestyle
Jul 29, 2021
651e699
using better name
Jul 29, 2021
0d244ad
added reminder
Jul 29, 2021
1ad9a2c
typing refactor
Jul 29, 2021
e0ee681
added test to be finished in fugure PRs
Jul 29, 2021
ff8b008
fixes command output README
Jul 29, 2021
a26b67d
do not fail when removing service
Jul 29, 2021
38cc182
log message for the user
Jul 29, 2021
56aa2ce
dynamic_sidecar_env_vars no longer contains obsucured password
Jul 29, 2021
7ad6f3f
empty string is treated as None
Jul 29, 2021
02b07d9
fixes broken behaviour
Jul 29, 2021
0b67932
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jul 30, 2021
5f725f0
codestyle
Jul 30, 2021
2564483
services are now queried for availability
Jul 30, 2021
2740b86
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jul 30, 2021
c6e3da1
avoids GC restarts upon errors
Jul 30, 2021
98481c8
added get_services timeout
Jul 30, 2021
1a5ec7d
locking is not required when recoviring the state
Jul 30, 2021
1b8895d
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jul 30, 2021
251b781
refactoring and renaming
Jul 30, 2021
196ef62
speeding up orphaned services removal
Jul 30, 2021
9e8d084
stopping services no longer hang on first error
Jul 30, 2021
20aefb0
stopping services will no longer raise errors
Jul 30, 2021
477b680
extend doc
Jul 30, 2021
073696a
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Jul 30, 2021
11c10af
fixing tests
Jul 30, 2021
898dd7b
reverting changes
Jul 30, 2021
d9c3a58
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Aug 2, 2021
24b9c22
fixed worfklow file
Aug 2, 2021
72a73b9
refactor
Aug 2, 2021
88b02fd
will codeclimate compalin?
Aug 2, 2021
48976f6
enhancing performance
Aug 2, 2021
b60b74e
minor refactor
Aug 2, 2021
4f91b98
fixed test
Aug 2, 2021
2404833
@sanderegg review
Aug 2, 2021
0abd013
no longer fails on boot
Aug 2, 2021
2ae7934
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Aug 2, 2021
b06ee4a
reverting change
Aug 2, 2021
3e2e885
removing comment
Aug 2, 2021
aed839b
moved code to correct place and removed duplication
Aug 2, 2021
c081172
refactored
Aug 2, 2021
d8277eb
refactored and moved to director-v2
Aug 2, 2021
1882737
renamed functions
Aug 2, 2021
bf156b7
pylint
Aug 2, 2021
3f737fe
fixing "typo master" issues
Aug 2, 2021
cb55a20
fixed comment
Aug 2, 2021
5240c27
more typos
Aug 2, 2021
0fa0e37
refactored boot mode test
Aug 2, 2021
5329bc9
renaming and updating
Aug 2, 2021
861a4cf
@sanderegg refactor to try/except
Aug 2, 2021
fe6df17
fixing test after rename
Aug 2, 2021
e1016cd
removing autouse
Aug 2, 2021
d0c4000
removed autouse
Aug 2, 2021
1685038
making it clear from where fucntion calls come
Aug 2, 2021
df05035
moved to utils
Aug 2, 2021
6085961
fixing typing
Aug 2, 2021
07e7f5a
removing and renaming fixtures
Aug 2, 2021
6c50956
fixed import
Aug 2, 2021
6c52a4e
fixed failing test
Aug 3, 2021
7effea1
pylint
Aug 3, 2021
02a18f1
should fix issue with boot mode
Aug 3, 2021
88fbd07
removed unused dependency
Aug 3, 2021
4010e84
reverted requiremtns updates
Aug 3, 2021
b8bcbe6
giving test more time
Aug 3, 2021
82e3b75
fixing time bump
Aug 3, 2021
b73e3fa
reverting to old timeout
Aug 3, 2021
7d9065e
trying to remove randomly hanging code
Aug 3, 2021
4dddf36
CI does not like localhost to reference docker
Aug 3, 2021
8bb1176
put back registry
Aug 3, 2021
5c76784
refactor and docstrings
Aug 3, 2021
afa2bfc
refactor + update docstrings
Aug 3, 2021
4653345
removing autoreuse
Aug 3, 2021
38abf11
fixed too broad error capture and message logging
Aug 3, 2021
5cac1b8
refactor
Aug 3, 2021
033e224
uses erorr handling, updated docstring
Aug 3, 2021
ad2429c
fix garbage collector
Aug 3, 2021
e42d593
refactor common test parts
Aug 3, 2021
ead05fa
refactor tests
Aug 4, 2021
06b17cf
no longer return "null"
Aug 4, 2021
597d2e0
transfomed form system to integration test
Aug 4, 2021
741072f
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Aug 4, 2021
a848abe
fixing broken test
Aug 4, 2021
7f3ad32
fixing test again
Aug 4, 2021
a423fde
bumping to avoid timeout
Aug 4, 2021
822f74e
Merge remote-tracking branch 'upstream/master' into adding-service-si…
Aug 4, 2021
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
38 changes: 38 additions & 0 deletions .github/workflows/ci-testing-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,44 @@ jobs:
name: unit_api_server_coverage
path: codeclimate.unit_api_server_coverage.json

unit-test-service-sidecar:
name: "[unit] service-sidecar"
runs-on: ${{ matrix.os }}
strategy:
matrix:
python: [3.8]
GitHK marked this conversation as resolved.
Show resolved Hide resolved
os: [ubuntu-20.04]
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: setup docker
run: |
sudo ./ci/github/helpers/setup_docker_compose.bash
./ci/github/helpers/setup_docker_experimental.bash
./ci/github/helpers/setup_docker_buildx.bash
echo ::set-env name=DOCKER_BUILDX::1
- name: setup python environment
uses: actions/[email protected]
GitHK marked this conversation as resolved.
Show resolved Hide resolved
with:
python-version: ${{ matrix.python }}
- name: show system version
run: ./ci/helpers/show_system_versions.bash
- uses: actions/cache@v2
name: getting cached data
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: setup requirements
run: make -C services/service-sidecar ci-install-requirements
- name: pylint via tox
run: make -C services/service-sidecar ci-tox-pylint
- name: mypy via tox
run: make -C services/service-sidecar ci-tox-mypy
- name: tests via tox
run: make -C services/service-sidecar ci-tox-tests
GitHK marked this conversation as resolved.
Show resolved Hide resolved

unit-test-catalog:
name: "[unit] catalog"
runs-on: ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ nodenv: node_modules ## builds node_modules local environ (TODO)
pylint: ## Runs python linter framework's wide
/bin/bash -c "pylint --jobs=0 --rcfile=.pylintrc $(strip $(shell find services packages -iname '*.py' \
-not -path "*egg*" \
-not -path "*service-sidecar*" \
GitHK marked this conversation as resolved.
Show resolved Hide resolved
-not -path "*migration*" \
-not -path "*datcore.py" \
-not -path "*sandbox*" \
Expand Down
35 changes: 35 additions & 0 deletions services/service-sidecar/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Planned]

- migrate to setup.py file
- add tests

## [Unreleased]

## [0.0.2] - 2020-07-15
### Added
- entry point to create containers without starting them
- entry point to stop running containers

### Modified
- moved more configurations to environment variables
- migrated to new project structure, after project was moved to osparc

## [0.0.1] - 2020-07-14
### Added
- FastAPI based service
- environs to manage configuration
- basic in memory storage , which can be easily extended for future needs
- async command execution of files
- context manger for to cleanup files after usage
- `docker-compose up` like entry point
- `docker-compose down` like entry point
- entry point to list docker-compose started container
- entry point to recover a container's logs
- entry point to inspect a container
- all spawned services and networks are removed when receiving `SIGTERM`
147 changes: 147 additions & 0 deletions services/service-sidecar/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
ARG PYTHON_VERSION="3.8.4"
FROM python:${PYTHON_VERSION}-slim-buster as base
#
# USAGE:
# cd sercices/service-sidecar
# docker build -f Dockerfile -t service-sidecar:prod --target production ../../
# docker run service-sidecar:prod
#
# REQUIRED: context expected at ``osparc-simcore/`` folder because we need access to osparc-simcore/packages

LABEL maintainer="Andrei Neagu <[email protected]>"

RUN set -eux; \
apt-get update; \
apt-get install -y gosu; \
rm -rf /var/lib/apt/lists/*; \
# verify that the binary works
gosu nobody true

# simcore-user uid=8004(scu) gid=8004(scu) groups=8004(scu)
ENV SC_USER_ID=8004 \
SC_USER_NAME=scu \
SC_BUILD_TARGET=base \
SC_BOOT_MODE=default

RUN adduser \
--uid ${SC_USER_ID} \
--disabled-password \
--gecos "" \
--shell /bin/sh \
--home /home/${SC_USER_NAME} \
${SC_USER_NAME}

# Sets utf-8 encoding for Python et al
ENV LANG=C.UTF-8
# Turns off writing .pyc files; superfluous on an ephemeral container.
ENV PYTHONDONTWRITEBYTECODE=1 \
VIRTUAL_ENV=/home/scu/.venv
# Ensures that the python and pip executables used
# in the image will be those from our virtualenv.
ENV PATH="${VIRTUAL_ENV}/bin:$PATH"


# -------------------------- Build stage -------------------
# Installs build/package management tools and third party dependencies
#
# + /build WORKDIR
#
FROM base as build

ENV SC_BUILD_TARGET=build

RUN apt-get update &&\
apt-get install -y --no-install-recommends \
build-essential

# NOTE: python virtualenv is used here such that installed
# packages may be moved to production image easily by copying the venv
RUN python -m venv ${VIRTUAL_ENV}

RUN pip install --upgrade --no-cache-dir \
pip~=20.2.2 \
wheel \
setuptools

WORKDIR /build

# install base 3rd party dependencies
# NOTE: copies to /build to avoid overwriting later which would invalidate this layer
COPY --chown=scu:scu services/service-sidecar/requirements/_base.txt .
RUN pip --no-cache-dir install -r _base.txt

# --------------------------Cache stage -------------------
# CI in master buils & pushes this target to speed-up image build
#
# + /build
# + services/service-sidecar [scu:scu] WORKDIR
#
FROM build as cache

ENV SC_BUILD_TARGET cache

COPY --chown=scu:scu packages /build/packages
COPY --chown=scu:scu services/service-sidecar /build/services/service-sidecar

WORKDIR /build/services/service-sidecar

RUN pip --no-cache-dir install -r requirements/prod.txt &&\
pip --no-cache-dir list -v


# --------------------------Production stage -------------------
# Final cleanup up to reduce image size and startup setup
# Runs as scu (non-root user)
#
# + /home/scu $HOME = WORKDIR
# + services/service-sidecar [scu:scu]
#
FROM base as production

ENV SC_BUILD_TARGET=production \
SC_BOOT_MODE=production

ENV PYTHONOPTIMIZE=TRUE

WORKDIR /home/scu

# Starting from clean base image, copies pre-installed virtualenv from cache
COPY --chown=scu:scu --from=cache ${VIRTUAL_ENV} ${VIRTUAL_ENV}

# Copies booting scripts
COPY --chown=scu:scu services/scheduler/docker services/scheduler/docker
RUN chmod +x services/scheduler/docker/*.sh

HEALTHCHECK --interval=30s \
--timeout=20s \
--start-period=30s \
--retries=3 \
CMD ["python3", "services/service-sidecar/docker/healthcheck.py", "http://localhost:8000/"]

EXPOSE 8000

ENTRYPOINT [ "/bin/sh", "services/service-sidecar/docker/entrypoint.sh" ]
CMD ["/bin/sh", "services/service-sidecar/docker/boot.sh"]


# --------------------------Development stage -------------------
# Source code accessible in host but runs in container
# Runs as myu with same gid/uid as host
# Placed at the end to speed-up the build if images targeting production
#
# + /devel WORKDIR
# + services (mounted volume)
#
FROM build as development

ENV SC_BUILD_TARGET=development

WORKDIR /devel

RUN chown -R scu:scu ${VIRTUAL_ENV}

EXPOSE 8000
EXPOSE 3000

ENTRYPOINT ["/bin/sh", "services/service-sidecar/docker/entrypoint.sh"]
CMD ["/bin/sh", "services/service-sidecar/docker/boot.sh"]
59 changes: 59 additions & 0 deletions services/service-sidecar/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
include ../../scripts/common.Makefile

APP_NAME := $(notdir $(CURDIR))

.DEFAULT_GOAL := help

.PHONY: help
help: ## display this message
@awk 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:space:]_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

.PHONY: _ensure-in-venv
_ensure-in-venv:
@python3 -c "import os; os.environ['VIRTUAL_ENV']" || (echo "\n>>>> You are not in a virtualenv. Activate one <<<<\n"; exit 1)

.PHONY: reqs
reqs: _ensure-in-venv ## compiles pip requirements (.in -> .txt)
@$(MAKE_C) requirements reqs

.PHONY: compile-dependencies
compile-dependencies: _ensure-in-venv ## snapshot test & package dependencies
@pip-compile --build-isolation requirements/_base.in --output-file requirements/_base.txt
@pip-compile --build-isolation requirements/_test.in --output-file requirements/_test.txt

.PHONY: install-dev-dependencies
install-dev-dependencies: _ensure-in-venv ## install depenencies for development
@pip install -r requirements/_base.txt

.PHONY: install-dev-dependencies
install-dev-dependencies: _ensure-in-venv ## install depenencies for development
@pip install -r requirements/_base.txt

.PHONY: dev-run
dev-run: _ensure-in-venv ## starts the container on its own
@docker run -it --rm \
-p 8000:8000 \
-v $(CURDIR):/devel/services/service-sidecar \
local/service-sidecar:development

.PHONY: ci-tox-pylint
ci-tox-pylint: ## runs pylint in a new enviornment
@tox -r -e pylint

.PHONY: ci-tox-mypy
ci-tox-mypy: ## runs mypy in a new enviornment
@tox -r -e mypy

.PHONY: ci-tox-tests
ci-tox-tests: ## runs tests with coverage in a new enviornment
@tox -r -e py38,report

.PHONY: ci-install-requirements
ci-install-requirements: ## runs tests with coverage in a new enviornment
@pip install -r requirements/dev.txt

.PHONY: run-github-action-locally
run-github-action-locally: ## runs the defined github action from the workflow locally
# Note: ⚡ act is required https://github.com/nektos/act
# Note: ⚠️ "act-environments-ubuntu:18.04" image is 18Gb takes a lot the first time
@act -C ../../. -P ubuntu-18.04=nektos/act-environments-ubuntu:18.04 -j unit-test-service-sidecar
1 change: 1 addition & 0 deletions services/service-sidecar/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.2
36 changes: 36 additions & 0 deletions services/service-sidecar/docker/boot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
set -o errexit
set -o nounset

IFS=$(printf '\n\t')

INFO="INFO: [$(basename "$0")] "

# BOOTING application ---------------------------------------------
echo "$INFO" "Booting in ${SC_BOOT_MODE} mode ..."
echo "$INFO" "User :$(id "$(whoami)")"
echo "$INFO" "Workdir : $(pwd)"

if [ "${SC_BUILD_TARGET}" = "development" ]; then
echo "$INFO" "Environment :"
printenv | sed 's/=/: /' | sed 's/^/ /' | sort
echo "$INFO" "Python :"
python --version | sed 's/^/ /'
command -v python | sed 's/^/ /'

cd services/service-sidecar || exit 1
pip --quiet --no-cache-dir install -r requirements/dev.txt
cd - || exit 1
echo "$INFO" "PIP :"
pip list | sed 's/^/ /'
fi

# RUNNING application ----------------------------------------
if [ "${SC_BOOT_MODE}" = "debug-ptvsd" ]
then
# NOTE: ptvsd is programmatically enabled inside of the service
# this way we can have reload in place as well
exec uvicorn sidecar.app:app --reload --host 0.0.0.0
else
exec service-sidecar-startup
fi
Loading