Skip to content

Commit

Permalink
feat(package): add an instruction to run docker-compose.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
yunielrc committed Sep 15, 2023
1 parent d0eda52 commit a93a2ba
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 10 deletions.
25 changes: 21 additions & 4 deletions Vedvfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,31 @@ FROM admin@manjaro/manjaro-gnome-22.1.3-x86_64

WORKDIR /home/vedv/ydf

RUN sudo pacman-mirrors --fasttrack
# update the system
RUN sudo pacman-mirrors --fasttrack && sudo pacman -Syu --noconfirm --needed

# install gnome base system
RUN sudo -H flatpak install --assumeyes --noninteractive io.github.andreibachim.shortcut

# install dev dependencies
COPY packages.env .

RUN mkdir tools
COPY tools/install-run-manjaro tools
COPY tools/install-dev-manjaro.vedv tools
COPY packages.env .
RUN tools/install-dev-manjaro.vedv

RUN tools/install-run-manjaro && tools/install-dev-manjaro.vedv
# install runtime dependencies
## yay
RUN sudo pacman -S --noconfirm --needed yay && \
source ./packages.env && \
yay -S --noconfirm --needed "\${PKG_RUN_MANJARO_YAY[@]}"
## snapd
RUN sudo pacman -S --noconfirm --needed snapd && \
sudo systemctl enable apparmor && \
sudo systemctl enable snapd.apparmor && \
sudo systemctl enable snapd && \
sudo ln -vs /var/lib/snapd/snap /snap
## docker
RUN sudo pacman -S --noconfirm --needed docker docker-compose && \
sudo systemctl enable docker && \
sudo usermod -aG docker "\$USER"
21 changes: 18 additions & 3 deletions src/usr/lib/ydf/components/package/ydf-package-service.bash
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fi
# readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall apt install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"

readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON=''
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall install @pacman @yay @flatpak @snap postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall install @pacman @yay @flatpak @snap docker_compose:docker-compose.yml postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
# readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"

#
Expand Down Expand Up @@ -175,6 +175,19 @@ ydf::package_service::__instruction_@snap() {
eval sudo -H snap install "${snap_pkg_name:-"$pkg_name"}"
}

#
# Execute docker-compose.yml instruction
#
# Arguments:
# pkg_name string package name
#
# Returns:
# 0 on success, non-zero on error.
#
ydf::package_service::__instruction_docker_compose() {
docker compose up -d
}

#
# Install a ydotfile package from a directory
#
Expand Down Expand Up @@ -224,9 +237,11 @@ ydf::package_service::install_one_from_dir() {
}

for _instr in "${instr_arr[@]}"; do
local ifunction="ydf::package_service::__instruction_${_instr}"
local ifunc_partial_name="${_instr%%:*}"
local ifile_name="${_instr##*:}"
local ifunction="ydf::package_service::__instruction_${ifunc_partial_name}"

if [[ ! -f "./${_instr}" ]]; then
if [[ ! -f "./${ifile_name}" ]]; then
continue
fi

Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/packages/0freedom-fail/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

services:
webapp:
image: hello-world
ports:
- "8000:8000"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
webapp:
container_name: hello_world
image: hello-world
ports:
- "8000:8000"
1 change: 1 addition & 0 deletions tests/fixtures/packages/9hello-world@dockercomp/install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo '8go@snap: install succeed'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo '8go@snap: postinstall succeed'
1 change: 1 addition & 0 deletions tests/fixtures/packages/9hello-world@dockercomp/preinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo '8go@snap: preinstall succeed'
15 changes: 15 additions & 0 deletions tests/usr/lib/ydf/components/package/ydf-package-command.f.bats
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,18 @@ com.github.tchx84.Flatseal: postinstall succeed"
assert_success
assert_output --partial "/bin/multipass"
}

# Tests for ydf package install
@test "ydf package install ./9hello-world@dockercomp Should succeed" {
local -r _package_dir="${TEST_FIXTURES_DIR}/packages/9hello-world@dockercomp"

run ydf package install "$_package_dir"

assert_success
assert_output --partial "Container hello_world Started"

run docker container ls -qaf "name=hello_world"

assert_success
assert [ -n "$output" ]
}
25 changes: 23 additions & 2 deletions tests/usr/lib/ydf/components/package/ydf-package-service.i.bats
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ setup() {
ydf::package_service::get_instructions_names() {
assert_equal "$*" ''

echo 'preinstall postinstall'
echo 'preinstall postinstall docker_compose:docker-compose.yml'
}
ydf::package_service::__instruction_instruction1() {
assert_equal "$*" '0freedom-fail'
Expand All @@ -177,12 +177,17 @@ setup() {
assert_equal "$*" '0freedom-fail'
echo preinstall
}
ydf::package_service::__instruction_docker_compose() {
assert_equal "$*" '0freedom-fail'
echo docker_compose
}

run ydf::package_service::install_one_from_dir "$_package_dir"

assert_success
assert_output "preinstall
postinstall"
postinstall
docker_compose"
}

# Tests for ydf::package_service::__instruction_install()
Expand Down Expand Up @@ -263,3 +268,19 @@ postinstall"

assert_output --partial 'bin/go'
}

# Tests for ydf::package_service::__instruction_docker_compose()
@test "ydf::package_service::__instruction_docker_compose() Should succeed" {

cd "${TEST_FIXTURES_DIR}/packages/9hello-world@dockercomp"

run ydf::package_service::__instruction_docker_compose '9hello-world@dockercomp'

assert_success
assert_output --partial "Container hello_world Started"

run docker container ls -qaf "name=hello_world"

assert_success
assert [ -n "$output" ]
}
2 changes: 1 addition & 1 deletion tools/ct-clean-exec
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fi

echo
echo ">>Copying files to container"
echo "Attention: if the container is starting it can take up to 30 seconds before the files are copied"
echo ">>>Attention: if the container is starting it can take up to 30 seconds before the files are copied"
vedv container copy --no-vedvfileignore "$VEDV_CONTAINER_NAME" . .
echo ">>Files copied"

Expand Down
6 changes: 6 additions & 0 deletions tools/install-run-manjaro
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ sudo ln -vs /var/lib/snapd/snap /snap
echo ">>Attention: log out and back in again, or restart your system, to ensure snap’s paths are updated correctly"

# sudo snap install core

# Install docker
sudo pacman -S --noconfirm --needed docker docker-compose
sudo systemctl enable docker --now

sudo usermod -aG docker "$USER"

0 comments on commit a93a2ba

Please sign in to comment.