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

Any objection if I add Dockerfile here ? #869

Closed
glimchb opened this issue Jul 6, 2024 · 11 comments · Fixed by #875
Closed

Any objection if I add Dockerfile here ? #869

glimchb opened this issue Jul 6, 2024 · 11 comments · Fixed by #875

Comments

@glimchb
Copy link
Contributor

glimchb commented Jul 6, 2024

wiki page https://github.com/stefanberger/swtpm/wiki/Dockerfiles is not enough...

something like this is super easy and helpful:

$ cat Dockerfile
FROM debian:12.6-slim

RUN apt-get update && \
    apt-get install --no-install-recommends -y swtpm=0.7.1-1.3 && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["/usr/bin/swtpm"]

lint passed:

$ docker run --rm -i ghcr.io/hadolint/hadolint < Dockerfile
$

build:

$ docker build -t swtpm:0.7.1 - < Dockerfile
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM debian:12.6-slim
 ---> 3eeb141ea1a1
Step 2/3 : RUN apt-get update &&     apt-get install --no-install-recommends -y swtpm=0.7.1-1.3 &&     apt-get clean &&     rm -rf /var/lib/apt/lists/*
 ---> Using cache
 ---> a9e31f6fdb72
Step 3/3 : ENTRYPOINT ["/usr/bin/swtpm"]
 ---> Using cache
 ---> 6fb7ab4b45f6
Successfully built 6fb7ab4b45f6
Successfully tagged swtpm:0.7.1

run:

$ docker run --rm -it swtpm:0.7.1 --version
TPM emulator version 0.7.1, Copyright (c) 2014-2021 IBM Corp.
@stefanberger
Copy link
Owner

Regarding your title: a Dockerfile for swtpm should probably install the swtpm from the git repo rather than a specific old version from a distro

@glimchb
Copy link
Contributor Author

glimchb commented Jul 8, 2024

Regarding your title: a Dockerfile for swtpm should probably install the swtpm from the git repo rather than a specific old version from a distro

sure, I can do that, absolutely
just wanted to get general agreement to work on this from the maintainer
if agreed, I will create PR
I can also do a matrix of 3 last versions to build and publish or just do the latest and then all future ones...

@stefanberger
Copy link
Owner

Regarding your title: a Dockerfile for swtpm should probably install the swtpm from the git repo rather than a specific old version from a distro

sure, I can do that, absolutely just wanted to get general agreement to work on this from the maintainer if agreed, I will create PR I can also do a matrix of 3 last versions to build and publish or just do the latest and then all future ones...

My preference would be that I don't have to deal much with updating the versions installed in the container and the version of the underlying distro and that others don't feel the need to add Dockerfiles for their favorite distro because then it becomes endless.

@glimchb
Copy link
Contributor Author

glimchb commented Jul 8, 2024

My preference would be that I don't have to deal much with updating the versions installed in the container and the version of the underlying distro and that others don't feel the need to add Dockerfiles for their favorite distro because then it becomes endless.

Yep, understood, minimal support is a requirement.

@lmussier
Copy link

Hi @glimchb, if I may, is there any chance that your contribution will lead to a container where we can use swtpm seamlessly?
I'm strugeling to find a way to have an image where swtpm would run and be the responder of tpm2-tools / tpm2-openssl for instance.

@stefanberger
Copy link
Owner

FYI: I am testing swtpm across distros in this project here: https://github.com/stefanberger/swtpm-distro-compile/

Maybe you can derive a Dockerfile from either one of these. Alpine seems to be a distro that produces a small image iirc.

@glimchb
Copy link
Contributor Author

glimchb commented Jul 18, 2024

@stefanberger I also saw this repo... it that maintained ?
https://github.com/tpm2-software/tpm2-software-container
?

@glimchb
Copy link
Contributor Author

glimchb commented Jul 18, 2024

Hi @glimchb, if I may, is there any chance that your contribution will lead to a container where we can use swtpm seamlessly? I'm strugeling to find a way to have an image where swtpm would run and be the responder of tpm2-tools / tpm2-openssl for instance.

@lmussier
While I work on the dockerfile in this repo, I already deployed example in my project using debian container.
It works seamlessly both swtpm and tpm2tools, docker-compose is testing this
https://github.com/opiproject/sztp/blob/3c77452310bdcb3e8bb1da9bb6d8e6839f2c1dff/docker-compose.yml#L254-L279

let me know if that works, I will try to replicate same behavior here, just using latest code instead of DEB pre-built package...

glimchb added a commit to glimchb/swtpm that referenced this issue Jul 18, 2024
Fixed stefanberger#869

Used multi-stage build here to reduce final image size.
Builder should have packages for dev and compile.
Final image should only have dependencies for runtime.

Building is simple using `docker build .` command.

Next patch will add:
- linter
- build
- tpm2 tools testing

Signed-off-by: Boris Glimcher <[email protected]>
glimchb added a commit to glimchb/swtpm that referenced this issue Jul 18, 2024
Fixes stefanberger#869

Using popular Hadolint linter for dockers.
Using standard GitHub action for building.

Build will also publish to GHCR after PR is merged, not before.

Signed-off-by: Boris Glimcher <[email protected]>
glimchb added a commit to glimchb/swtpm that referenced this issue Jul 18, 2024
Fixed stefanberger#869

Used multi-stage build here to reduce final image size.
Builder should have packages for dev and compile.
Final image should only have dependencies for runtime.

Building is simple using `docker build .` command.

Or `docker build --build-arg="LIBTPMS_BRANCH=v0.9.6" .`
if you want another branch/tag of libtpms.

Next patch will add:
- linter
- build
- tpm2 tools testing

Signed-off-by: Boris Glimcher <[email protected]>
glimchb added a commit to glimchb/swtpm that referenced this issue Jul 18, 2024
Fixes stefanberger#869

Using popular Hadolint linter for dockers.
Using standard GitHub action for building.

Build will also publish to GHCR after PR is merged, not before.

Signed-off-by: Boris Glimcher <[email protected]>
glimchb added a commit to glimchb/swtpm that referenced this issue Jul 18, 2024
Fixed stefanberger#869

Used multi-stage build here to reduce final image size.
Builder should have packages for dev and compile.
Final image should only have dependencies for runtime.

Building is simple using `docker build .` command.

Or `docker build --build-arg="LIBTPMS_BRANCH=v0.9.6" .`
if you want another branch/tag of libtpms.

Next patch will add:
- linter
- build
- tpm2 tools testing

Signed-off-by: Boris Glimcher <[email protected]>
glimchb added a commit to glimchb/swtpm that referenced this issue Jul 18, 2024
Fixes stefanberger#869

Using popular Hadolint linter for dockers.
Using standard GitHub action for building.

Build will also publish to GHCR after PR is merged, not before.

Signed-off-by: Boris Glimcher <[email protected]>
@glimchb
Copy link
Contributor Author

glimchb commented Jul 18, 2024

sorry it took me few days - I was ooo

PR submitted for review based on alpine docker
I also added github actions for lint, build and test
I also added docker compose for test and example
Any comments are welcomed

@glimchb
Copy link
Contributor Author

glimchb commented Jul 18, 2024

@stefanberger

I publish docker image automatically to ghcr.io/stefanberger/swtpm so peopel can download and use it without need to rebuild all the time themselves...

if you want to publish docker also to https://hub.docker.com/u/stefanberger everything is ready, just to have 2 secrets defined in this repo settings: secrets.DOCKERHUB_USERNAME and secrets.DOCKERHUB_TOKEN

glimchb added a commit to glimchb/swtpm that referenced this issue Jul 18, 2024
Fixed stefanberger#869

Used multi-stage build here to reduce final image size.
Builder should have packages for dev and compile.
Final image should only have dependencies for runtime.

Building is simple using `docker build .` command.

Or `docker build --build-arg="LIBTPMS_BRANCH=v0.9.6" .`
if you want another branch/tag of libtpms.

Next patch will add:
- linter
- build
- tpm2 tools testing

Signed-off-by: Boris Glimcher <[email protected]>
glimchb added a commit to glimchb/swtpm that referenced this issue Jul 18, 2024
Fixes stefanberger#869

Using popular Hadolint linter for dockers.
Using standard GitHub action for building.

Build will also publish to GHCR after PR is merged, not before.

Signed-off-by: Boris Glimcher <[email protected]>
stefanberger pushed a commit that referenced this issue Jul 18, 2024
Fixes #869

Using popular Hadolint linter for dockers.
Using standard GitHub action for building.

Build will also publish to GHCR after PR is merged, not before.

Signed-off-by: Boris Glimcher <[email protected]>
@glimchb
Copy link
Contributor Author

glimchb commented Jul 18, 2024

opened new #876 to publish to https://hub.docker.com/u/stefanberger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants