-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: Simplify helloworld demo to match helloworld test
The helloworld demo used a really complicated system to build the elf file on the host and then transfer it to the docker image. It's better to simply build it inside docker, as the test does. This commit copies Dockerfile, Makefile and helloworld.c from the test to the sample. The Makefile has been modified to still use enclave_config.json (the test wasn't using it).
- Loading branch information
Showing
3 changed files
with
34 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,11 @@ | ||
FROM alpine:3.8 | ||
FROM alpine:3.6 AS builder | ||
|
||
ARG UID | ||
ARG GID | ||
RUN apk add --no-cache gcc musl-dev | ||
|
||
USER root | ||
ADD *.c / | ||
RUN gcc -g -o helloworld helloworld.c | ||
|
||
# Build packages: build-base gcc wget git curl | ||
FROM alpine:3.6 | ||
|
||
RUN apk add --no-cache bash shadow sudo && \ | ||
addgroup -S alpine; \ | ||
adduser -S -G alpine -s /bin/bash user; \ | ||
echo "user ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/user && \ | ||
chmod 0440 /etc/sudoers.d/user | ||
|
||
WORKDIR /app | ||
RUN chown user:alpine /app | ||
USER user | ||
|
||
#ENV PS1="\[\033[31;40;1m\][\u@\h]\[\033[32;40;1m\] \W\[\033[33;40;1m\]>\[\033[0m\]" | ||
|
||
COPY --chown=user:alpine app/ . | ||
|
||
# Start from a Bash prompt | ||
CMD ["/bin/bash"] | ||
COPY --from=builder helloworld . | ||
ADD app /app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,41 @@ | ||
include ../../../tests/common.mk | ||
|
||
APP_ROOT=app | ||
PROG=${APP_ROOT}/helloworld | ||
PROG_NONPIE=${APP_ROOT}/helloworld-nonpie | ||
PROG_C=helloworld.c | ||
PROG=helloworld | ||
PROG_SRC=$(PROG).c | ||
IMAGE_SIZE=5M | ||
|
||
DISK_IMAGE=sgxlkl-helloworld.img | ||
IMAGE_SIZE=100M | ||
EXECUTION_TIMEOUT=60 | ||
|
||
SGXLKL_ROOT=../../.. | ||
SGXLKL_ENV=SGXLKL_VERBOSE=1 SGXLKL_KERNEL_VERBOSE=1 | ||
SGXLKL_HW_PARAMS=--hw-debug | ||
SGXLKL_SW_PARAMS=--sw-debug | ||
|
||
MUSL_CC=${SGXLKL_ROOT}/build/host-musl/bin/musl-gcc | ||
|
||
SGXLKL_STARTER=$(SGXLKL_ROOT)/build/sgx-lkl-run-oe | ||
|
||
ifeq ($(SGXLKL_VERBOSE),) | ||
SGXLKL_ENV=\ | ||
SGXLKL_VERBOSE=1 SGXLKL_KERNEL_VERBOSE=0 SGXLKL_TRACE_SIGNAL=0\ | ||
SGXLKL_TRACE_HOST_SYSCALL=0 SGXLKL_TRACE_LKL_SYSCALL=0 SGXLKL_TRACE_MMAP=0 | ||
else | ||
SGXLKL_ENV= | ||
endif | ||
|
||
SGXLKL_DISK_TOOL=${SGXLKL_ROOT}/tools/sgx-lkl-disk | ||
SGXLKL_GDB=${SGXLKL_ROOT}/tools/gdb/sgx-lkl-gdb | ||
SGXLKL_ROOTFS=sgx-lkl-rootfs.img | ||
|
||
.DELETE_ON_ERROR: | ||
.PHONY: all clean | ||
|
||
all: $(DISK_IMAGE) | ||
$(SGXLKL_ROOTFS): $(PROG_SRC) | ||
${SGXLKL_DISK_TOOL} create --size=${IMAGE_SIZE} --docker=./Dockerfile ${SGXLKL_ROOTFS} | ||
|
||
clean: | ||
rm -f $(DISK_IMAGE) $(PROG) $(PROG_NONPIE) | ||
|
||
$(PROG): $(PROG_C) | ||
${MUSL_CC} -fPIE -pie -o $@ $(PROG_C) | ||
gettimeout: | ||
@echo ${EXECUTION_TIMEOUT} | ||
|
||
# non-PIE executable are currently unsupported by SGX-LKL-OE | ||
$(PROG_NONPIE): $(PROG_C) | ||
${MUSL_CC} -fno-pie -no-pie -o $@ $(PROG_C) | ||
run: run-hw run-sw | ||
|
||
$(DISK_IMAGE): $(PROG) $(PROG_NONPIE) | ||
${SGXLKL_DISK_TOOL} create --size=${IMAGE_SIZE} --copy=./${APP_ROOT}/ ${DISK_IMAGE} | ||
run-gdb: run-hw-gdb | ||
|
||
run: run-hw | ||
run-hw: ${SGXLKL_ROOTFS} | ||
$(SGXLKL_ENV) $(SGXLKL_STARTER) $(SGXLKL_HW_PARAMS) --enclave-config enclave_config.json $(SGXLKL_ROOTFS) $(PROG) | ||
|
||
run-hw: $(DISK_IMAGE) | ||
${SGXLKL_ENV} ${SGXLKL_STARTER} --hw-debug --enclave-config enclave_config.json $(DISK_IMAGE) | ||
run-sw: ${SGXLKL_ROOTFS} | ||
$(SGXLKL_ENV) $(SGXLKL_STARTER) $(SGXLKL_SW_PARAMS) --enclave-config enclave_config.json $(SGXLKL_ROOTFS) $(PROG) | ||
|
||
run-hw-gdb: $(DISK_IMAGE) | ||
${SGXLKL_ENV} ${SGXLKL_GDB} --args ${SGXLKL_STARTER} --hw-debug --enclave-config enclave_config.json $(DISK_IMAGE) | ||
run-hw-gdb: ${SGXLKL_ROOTFS} | ||
$(SGXLKL_ENV) $(SGXLKL_GDB) --args $(SGXLKL_STARTER) $(SGXLKL_HW_PARAMS) --enclave-config enclave_config.json $(SGXLKL_ROOTFS) $(PROG) | ||
|
||
run-sw: $(DISK_IMAGE) | ||
${SGXLKL_ENV} ${SGXLKL_STARTER} --sw-debug --enclave-config enclave_config.json $(DISK_IMAGE) | ||
run-sw-gdb: ${SGXLKL_ROOTFS} | ||
$(SGXLKL_ENV) $(SGXLKL_GDB) --args $(SGXLKL_STARTER) $(SGXLKL_SW_PARAMS) --enclave-config enclave_config.json $(SGXLKL_ROOTFS) $(PROG) | ||
|
||
run-sw-gdb: $(DISK_IMAGE) | ||
${SGXLKL_ENV} ${SGXLKL_GDB} --args ${SGXLKL_STARTER} --sw-debug --enclave-config enclave_config.json $(DISK_IMAGE) | ||
clean: | ||
rm -f $(SGXLKL_ROOTFS) $(PROG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters