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

Stregsystemscontainer-buildscript #275

Open
wants to merge 6 commits into
base: next
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM fedora:latest

ARG workdir=/home/stregsystemet
ARG author="FRITFIT"

RUN dnf install python3-pip gcc python3-devel python3.7 -y
RUN dnf clean all

RUN mkdir $workdir
ADD ./ $workdir
WORKDIR $workdir
EXPOSE 8000/tcp
EXPOSE 8000/udp
LABEL org.opencontainers.image.authors=$author

RUN python3.7 -m venv venv
RUN /bin/bash -c "source venv/bin/activate && pip install -r requirements.txt"
RUN /bin/bash -c "source venv/bin/activate && python manage.py migrate"
CMD [ "/bin/bash", "-c", "source venv/bin/activate && python manage.py runserver 0:8000" ]
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ From then on
1. `python manage.py runserver`
2. ???
3. Profit

Using containers???
-------
There are two ways to create a stregsystem-image. One is to use the Dockerfile and your containerbuilder of choice. The other is to use the `build_container.sh` script, which will need `buildah` to work.
You will also need a container runtime (OCI Compliant) of to run Stregsystemet in a container.
Using `build_container.sh`, an image will be built with the name `stregsystem-container`.
To run the image with Podman, use the following command: `podman run -p 8000:8000 stregsystem-container`
Note that this will start Stregsystemet in production mode. If you want to start Stregsystemet with a test database, use the following command:
`podman run -p 8000:8000 --entrypoint '[ "/bin/bash", "-c", "source venv/bin/activate && python manage.py testserver --addrport 0:8000 stregsystem/fixtures/testdata.json" ]' stregsystem-container`

39 changes: 39 additions & 0 deletions build_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

#Sæt variablenavne. Dem bruger vi senere
imgname=stregsystem-container
authorname=FRITFIT
workdir=/home/stregsystemet

#Gem navnet på containeren. Kan også bygges fra bunden af, men så skal man til at bruge
#sin egen package manager til at bootstrappe billedet
#(wink wink nudge nudge til de archtrolde der nu findes i fit)
container=$(buildah from fedora)
#installer dependencies
buildah run $container dnf install python3-pip gcc python3-devel python3.6 -y
#slet midlertidige filer fra package manager
buildah run $container dnf clean all
#lav lokal folder til stregsystemet
buildah run $container mkdir $workdir
#kopier alle stregsystemets filer. TODO: Kopier kun dem, der er nødvendige
buildah add $container ./ $workdir
#sæt workingdir så vi ikke bliver sindssyge af at skulle indeksere den rigtige folder
buildah config --workingdir $workdir $container
#Lav venv
buildah run $container python3.6 -m venv venv
#installer deps fra requirements.txt
buildah run $container /bin/bash -c "source venv/bin/activate && pip install -r requirements.txt"
#Kør migrations
buildah run $container /bin/bash -c "source venv/bin/activate && python manage.py migrate"
#Åben port til stregsystemet
buildah config --port 8000 $container
#Sæt entrypoint
buildah config --cmd '[ "/bin/bash", "-c", "source venv/bin/activate && python manage.py runserver 0:8000" ]' $container
#sæt anden god information
buildah config --author $authorname --label name=$imgname $container
#Commit til et image
buildah commit $container $imgname

#Husk at rydde op efter os selv
buildah rm $container