Skip to content

Commit

Permalink
Dockerfile updated
Browse files Browse the repository at this point in the history
  • Loading branch information
0xvpr committed May 4, 2024
1 parent 47816ee commit c5c4d38
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 19 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
authors = [ "VPR <0xvpr@god.io>" ]
authors = [ "0xvpr <admin@0xvpr.io>" ]
name = "concept"
version = "1.0.0"
edition = "2021"
Expand All @@ -8,7 +8,6 @@ build = "build.rs"

[dependencies]
winapi = { version = "0.3.9", features = [ "fileapi", "winbase" ] }
tokio = { version = "1.0", features = ["full"] }

[profile.release]
lto = true
55 changes: 43 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# Created: February 12th, 2024

# Updated by: VPR
# Updated: February 12th, 2024
# Updated: May 2nd, 2024

FROM ubuntu:22.04
FROM ubuntu:24.04

# Set env to avoid user input interruption during installation
ENV TZ=America/New_York
Expand All @@ -24,18 +24,49 @@ RUN apt-get install -y --no-install-recommends \
mingw-w64-i686-dev \
mingw-w64-x86-64-dev \
mingw-w64-tools
RUN update-ca-certificates

# Create working environment
USER root
ENV HOME=/root
WORKDIR /var/concept-dev/concept
WORKDIR /var/opt/concept

# Copy sources
COPY res res
COPY src src
COPY config.toml config.toml
COPY build.rs build.rs
COPY rust-toolchain.toml rust-toolchain.toml
COPY Cargo.toml Cargo.toml
COPY Makefile Makefile

# Set docker user to local user uid:gid
ARG LOCAL_USER
ARG LOCAL_UID
ARG LOCAL_GID

RUN if getent group $LOCAL_GID > /dev/null; \
then \
groupmod -n $LOCAL_USER `getent group $LOCAL_GID | cut -f1 -d:`; \
else \
groupadd -g $LOCAL_GID $LOCAL_USER; \
fi

RUN if getent group $LOCAL_UID > /dev/null; \
then \
usermod -l $LOCAL_USER -d /home/$LOCAL_USER -m `getent passwd 1000 | cut -f1 -d:`; \
else \
useradd -m -u $LOCAL_UID -g $LOCAL_GID -s /bin/bash $LOCAL_USER; \
fi

RUN chown -R $LOCAL_USER:$LOCAL_USER /var/opt/concept

# Become user
USER $LOCAL_USER
ENV HOME=/home/$LOCAL_USER

# Install & configure Rust
RUN update-ca-certificates
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup install nightly
RUN rustup default nightly
RUN rustup target add x86_64-pc-windows-gnu --toolchain nightly
# RUN cargo build -Z build-std --target x86_64-pc-windows-gnu
RUN rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
RUN . $HOME/.profile && rustup install nightly
RUN . $HOME/.profile && rustup default nightly
RUN . $HOME/.profile && rustup target add x86_64-pc-windows-gnu --toolchain nightly
RUN . $HOME/.profile && rustup toolchain add nightly-x86_64-pc-windows-gnu
RUN . $HOME/.profile && rustup component add rust-src --toolchain nightly-x86_64-pc-windows-gnu
25 changes: 21 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
PROJECT = concept
CONTAINER = $(PROJECT)-dev

LOCAL_UID = $(shell id -u)
LOCAL_GID = $(shell id -g)
LOCAL_USER = $(shell whoami)
BUILD_ARGS = --build-arg LOCAL_USER="$(LOCAL_USER)" --build-arg LOCAL_UID="$(LOCAL_UID)" --build-arg LOCAL_GID="$(LOCAL_GID)"

USER_SHARED_DIR = $(shell pwd)/target
DOCKER_SHARED_DIR = /var/opt/$(PROJECT)/target

OWNER = $(LOCAL_USER):$(LOCAL_USER)
SHARED_VOLUME = $(USER_SHARED_DIR):$(DOCKER_SHARED_DIR)


all: docker-build
all: docker-run

.PHONY: docker-container
docker-container:
docker build --no-cache -f "Dockerfile" -t "$(PROJECT)-dev" .
docker build -f Dockerfile . -t "$(CONTAINER)" $(BUILD_ARGS)

.PHONY: docker-build
docker-build:
docker run -v "$(shell pwd):/var/$(PROJECT)-dev/$(PROJECT)" -u "root:root" "$(PROJECT)-dev" /bin/bash -c "cargo clean && cargo build --target x86_64-pc-windows-gnu"
docker run -v "$(SHARED_VOLUME)" -u "$(OWNER)" "$(CONTAINER)" /bin/bash -c ". /home/$(USER)/.profile && make build"

.PHONY: docker-run
docker-run:
docker run -itv "$(shell pwd):/var/$(PROJECT)-dev/$(PROJECT)" -u "root:root" "$(PROJECT)-dev"
docker-run: target
docker run -itv "$(SHARED_VOLUME)" -u "$(OWNER)" "$(CONTAINER)"

.PHONY: clean
clean:
Expand All @@ -27,3 +40,7 @@ build:
.PHONY: run
run:
target/x86_64-pc-windows-gnu/release/concept.exe

.PHONY: target
target:
mkdir -p target
2 changes: 1 addition & 1 deletion res/icon.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
id ICON "Viper.ico"
id ICON "viper.ico"

0 comments on commit c5c4d38

Please sign in to comment.