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

improve traefik config #57

Merged
merged 3 commits into from
Jan 5, 2024
Merged
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
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
AEOLUS_DOCKER_TAG=nightly
AEOLUS_HOST=aeolus-test.artemis.cit.tum.de
AEOLUS_HOST=aeolus-test.artemis.cit.tum.de
AEOLUS_DOCKER_BRANCH=develop
131 changes: 57 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,71 +105,63 @@ Generate with python main.py -dev generate -t cli -i examples/example-windfile-r
```bash
#!/usr/bin/env bash
set -e
# the repository aeolus is expected to be mounted into the container at /aeolus
# step set-java-container
# generated from step set-java-container
# original type was script
set-java-container () {
echo '⚙️ executing set-java-container'
export AEOLUS_INITIAL_DIRECTORY=${PWD}
export REPOSITORY_URL="https://github.com/ls1intum/Aeolus.git"

setjavacontainer () {
echo '⚙️ executing setjavacontainer'
set
}
# step set-c-container
# generated from step set-c-container
# original type was script
set-c-container () {
echo '⚙️ executing set-c-container'

setccontainer () {
echo '⚙️ executing setccontainer'
set
}
# step internal-action
# generated from step internal-action
# original type was script
internal-action () {
echo '⚙️ executing internal-action'

internalaction () {
echo '⚙️ executing internalaction'
echo "This is an internal action"

}
# step external-action_0
# generated from step external-action
# original type was internal
external-action_0 () {
local _current_lifecycle="${1}"
if [[ "${_current_lifecycle}" == "preparation" ]]; then
echo '⚠️ external-action_0 is excluded during preparation'
return 0
fi
if [[ "${_current_lifecycle}" == "working_time" ]]; then
echo '⚠️ external-action_0 is excluded during working_time'
return 0
fi
echo '⚙️ executing external-action_0'
WHO_TO_GREET="world"

externalaction_ () {
echo '⚙️ executing externalaction_'
echo "Hello ${WHO_TO_GREET}"
}
# step clean_up
# generated from step clean_up
# original type was script

clean_up () {
echo '⚙️ executing clean_up'
rm -rf aeolus/

}

# always steps
final_aeolus_post_action () {
set +e # from now on, we don't exit on errors
echo '⚙️ executing final_aeolus_post_action'
clean_up $_current_lifecycle
cd "${AEOLUS_INITIAL_DIRECTORY}"
clean_up "${_current_lifecycle}"
}


# main function
main () {
local _current_lifecycle="${1}"
if [[ "${1}" == "aeolus_sourcing" ]]; then
return 0 # just source to use the methods in the subshell, no execution
filocal _current_lifecycle="${1}"

local _script_name
_script_name=${BASH_SOURCE[0]:-$0}
trap final_aeolus_post_action EXIT
set-java-container $_current_lifecycle
set-c-container $_current_lifecycle
internal-action $_current_lifecycle
external-action_0 $_current_lifecycle

cd "${AEOLUS_INITIAL_DIRECTORY}"
bash -c "source ${_script_name} aeolus_sourcing; setjavacontainer \"${_current_lifecycle}\""
cd "${AEOLUS_INITIAL_DIRECTORY}"
bash -c "source ${_script_name} aeolus_sourcing; setccontainer \"${_current_lifecycle}\""
cd "${AEOLUS_INITIAL_DIRECTORY}"
bash -c "source ${_script_name} aeolus_sourcing; internalaction \"${_current_lifecycle}\""
cd "${AEOLUS_INITIAL_DIRECTORY}"
bash -c "source ${_script_name} aeolus_sourcing; externalaction_ \"${_current_lifecycle}\""
}

main $@
main "${@}"
```

And the generated Jenkinsfile would look like this:
Expand All @@ -187,6 +179,10 @@ pipeline {
parameters {
string(name: 'current_lifecycle', defaultValue: 'working_time', description: 'The current stage')
}
environment {
REPOSITORY_URL = 'https://github.com/ls1intum/Aeolus.git'
}

stages {
stage('aeolus') {
steps {
Expand All @@ -200,95 +196,82 @@ pipeline {
userRemoteConfigs: [[
credentialsId: 'artemis_gitlab_admin_credentials',
name: 'aeolus',
url: 'https://github.com/ls1intum/Aeolus.git'
url: "${REPOSITORY_URL}"
]]
])
}
}
}
// step set-java-container
// generated from step set-java-container
// original type was script
stage('set-java-container') {
agent {
docker {
image 'ls1tum/artemis-maven-template:java17-20'
args '-v ${PWD}:/aeolus --cpus "2" --memory "2g" --memory-swap "2g" --pids-limit "1000"'
args '--cpus "2" --memory "2g" --memory-swap "2g" --pids-limit "1000"'
}
}
steps {
echo '⚙️ executing set-java-container'
sh '''
set
'''
set
'''
}
}
// step set-c-container
// generated from step set-c-container
// original type was script
stage('set-c-container') {
agent {
docker {
image 'ghcr.io/ls1intum/artemis-c-docker:latest'
args '--cpus "2" --memory "2g" --memory-swap "2g" --pids-limit "1000"'
}
}
steps {
echo '⚙️ executing set-c-container'
sh '''
set
'''
set
'''
}
}
// step internal-action
// generated from step internal-action
// original type was script
stage('internal-action') {
agent {
docker {
image 'ls1tum/artemis-maven-template:java17-20'
args '-v ${PWD}:/aeolus --cpus "2" --memory "2g" --memory-swap "2g" --pids-limit "1000"'
args '--cpus "2" --memory "2g" --memory-swap "2g" --pids-limit "1000"'
}
}
steps {
echo '⚙️ executing internal-action'
sh '''
echo "This is an internal action"
'''
echo "This is an internal action"

'''
}
}
// step external-action_0
// generated from step external-action
// original type was internal
stage('external-action_0') {
agent {
docker {
image 'ls1tum/artemis-maven-template:java17-20'
args '-v ${PWD}:/aeolus --cpus "2" --memory "2g" --memory-swap "2g" --pids-limit "1000"'
args '--cpus "2" --memory "2g" --memory-swap "2g" --pids-limit "1000"'
}
}
when {
anyOf {
expression { params.current_lifecycle != 'working_time' }
expression { params.current_lifecycle != 'preparation' }
expression { params.current_lifecycle != 'working_time' }
}
}
environment {
WHO_TO_GREET = "world"
}
steps {
echo '⚙️ executing external-action_0'
echo "Hello ${WHO_TO_GREET}"
sh '''
echo "Hello ${WHO_TO_GREET}"
'''
}
}
}
post {
// step clean_up
// generated from step clean_up
// original type was script
always {
echo '⚙️ executing clean_up'
sh '''
rm -rf aeolus/

'''
}
}
Expand Down
4 changes: 1 addition & 3 deletions cli/templates/Jenkinsfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ pipeline {
checkout([$class: 'GitSCM',
branches: [[name: '{{ repository.branch }}']],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [[
{%- if metadata.gitCredentials %}
credentialsId: '{{ metadata.gitCredentials }}',
{%- endif %}
name: '{{ name }}',
{%- set url = '${%s}' % repo_metadata[name]["url"] %}
url: '{{ url }}'
url: "{{ url }}"
]]
])
}
Expand Down
2 changes: 1 addition & 1 deletion cli/templates/cli.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ main () {
{% endif %}
{%- for function in functions %}
{%- if needs_lifecycle_parameter -%}
{%- if needs_subshells -%}
{%- if needs_subshells %}
cd {{ initial_directory }}
bash -c "source ${_script_name} aeolus_sourcing; {{ function }} \"${_current_lifecycle}\""
{%- else %}
Expand Down
3 changes: 2 additions & 1 deletion deployment/aeolus-docker
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ function start {
local pr_branch=$2

echo "Starting aeolus with PR tag: $pr_tag and branch: $pr_branch"
rm -rf Aeolus
cd $WORKING_DIR || exit
rm -rf Aeolus
git clone https://github.com/ls1intum/Aeolus.git -b "$pr_branch" Aeolus
sed -i "s/AEOLUS_DOCKER_BRANCH=.*/AEOLUS_DOCKER_BRANCH='$pr_branch'/g" $ENV_FILE
sed -i "s/AEOLUS_DOCKER_TAG=.*/AEOLUS_DOCKER_TAG='$pr_tag'/g" $ENV_FILE
if [ ! -f "$WORKING_DIR/docker.env" ]; then
wget -O "$WORKING_DIR/docker.env" https://raw.githubusercontent.com/ls1intum/Aeolus/develop/.env.example
Expand Down
2 changes: 1 addition & 1 deletion deployment/traefik/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik"
- 'traefik.http.routers.aeolus-api.rule=(Host(`${AEOLUS_HOST}`) && PathPrefix("/api"))'
- 'traefik.http.routers.aeolus-api.rule=(Host(`${AEOLUS_HOST}`) && (PathPrefix("/api") || Path("/openapi.json") || Path("/docs")))'
- "traefik.http.routers.aeolus-api.entrypoints=https"
- "traefik.http.routers.aeolus-api.tls=true"
- "traefik.http.routers.aeolus-api.tls.certResolver=leresolver"
Expand Down
Loading