FROM nvidia/cudagl:11.4.2-devel-ubuntu20.04
LABEL Author="Nanahira <nanahira@momobako.com>"

RUN rm -rf /etc/apt/sources.list.d/* && \
	apt update && \
	env DEBIAN_FRONTEND=noninteractive apt -y install wget tar git ca-certificates build-essential ffmpeg libfreetype6-dev libevent-dev libsqlite3-dev libgl1-mesa-dev libglu-dev liblua5.3-dev libxxf86vm-dev p7zip-full libffmpeg-nvenc-dev && \
	rm -rf /var/tmp/* /tmp/* /var/lib/apt/lists/* /var/log/* /var/cache/apt/archives/*


WORKDIR /usr/src/app
COPY . ./

	# irrlicht
RUN git clone --depth=1 https://code.mycard.moe/mycard/irrlicht-new irrlicht && \
	# premake
	wget -O - https://github.com/premake/premake-core/releases/download/v5.0.0-beta1/premake-5.0.0-beta2-linux.tar.gz | tar zfx - && \
	./premake5 gmake --no-use-irrklang --lua-deb && \
	# build
	cd build && make config=release -j$(nproc) && cd .. && \
	mv bin/release/YGOPro ./ygopro && \
	strip ygopro && \
	# images
	wget -O ygopro-images-zh-CN.zip https://cdn02.moecube.com:444/images/ygopro-images-zh-CN.zip && \
	7z x -y -opics ygopro-images-zh-CN.zip && \
	rm -rf ygopro-images-zh-CN.zip && \
	# sound
	wget -O - https://code.mycard.moe/mycard/ygopro-sounds/-/archive/master/ygopro-sounds-master.tar.gz | tar zfx - && \
	mv ygopro-sounds-master/sound/* sound && \
	rm -rf ygopro-sounds-master && \
	# fonts
	mkdir fonts && \
	cd fonts && \
	wget -O - https://cdn02.moecube.com:444/ygopro-fonts.tar.gz | tar zfx - && \
	cd .. && \
	# cleanup
	cp -rf system.conf system_user.conf && \
	rm -rf bin obj build premake5 irrlicht_linux

RUN ln -s /usr/local/cuda/compat/libcuda.so.1 /usr/lib/x86_64-linux-gnu/libcuda.so.1

ENV DISPLAY ":0"
CMD ["./record-video.sh"]
