Skip to content

Template Repository #353

@PeterKnealeCMRI

Description

@PeterKnealeCMRI

I've enjoyed using the your tool, it really helps to bring certainty to the bash scripting process ♥️

One thing I found myself looking for was a template repository that could be cloned as a starting point..
Perhaps this is something available elsewhere that I just havent come across.

https://github.com/shellspec/shellspec-demo/tree/master is close but not quite there.

Happy to contribute a demo repo if it helps but the idea being:

A folder structure similar to that shown in the readme.

<PROJECT-ROOT> directory
├─ .shellspec                       [mandatory]
├─ .shellspec-local                 [optional] Ignore from version control
├─ .shellspec-quick.log             [optional] Ignore from version control
├─ report/                          [optional] Ignore from version control
├─ coverage/                        [optional] Ignore from version control
│
├─ bin/
│   ├─ your_script1.sh
│              :
├─ lib/
│   ├─ your_library1.sh
│              :
│
├─ spec/ (also <HELPERDIR>)
│   ├─ spec_helper.sh               [recommended]
│   ├─ banner[.md]                  [optional]
│   ├─ support/                     [optional]
│   │
│   ├─ bin/
│   │   ├─ your_script1_spec.sh
│   │             :
│   ├─ lib/
│   │   ├─ your_library1_spec.sh

Multistage docker builds

Adding a docker multistage build so that we can be sure that the script is executing in exactly the same environment as where the tests passed.

##################################################################
# BASE - common dependencies and files
##################################################################
FROM debian:bullseye AS base

# Install common dependencies
RUN apt-get update && apt-get install -y \
    bash \
    gawk \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /app

# Copy application files
COPY script.sh /app/
COPY xxxxxxxxxxxxx.txt.gz /app/

# Make script executable
RUN chmod +x /app/script.sh


##################################################################
# TEST - derives from base and adds test dependencies
##################################################################
FROM base AS test

# Install ShellSpec
RUN curl -fsSL https://git.io/shellspec | sh -s -- --yes

# Copy test files
COPY spec/ /app/spec/
COPY .shellspec /app/

# Run the tests
ENTRYPOINT ["sh", "-c", "SHELLSPEC_TTY=0 /root/.local/bin/shellspec --format documentation"]

##################################################################
# PRODUCTION - derives from base (no test dependencies)
##################################################################
FROM base AS production
ENTRYPOINT ["./script.sh"]

devcontainer setup

Something minimal that makes working on the script within a controlled and reproducible environment

{
	"name": "Shellspec",
	"image": "mcr.microsoft.com/devcontainers/base:bullseye",
	"postCreateCommand": "sudo apt update && sudo apt install -y gawk curl && curl -fsSL https://git.io/shellspec | sh -s 0.28.1 --yes"
}

github actions

Using the multistage builds to test the image prior to pushing

name: Build and Test Docker Image

jobs:
  build-and-test:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Test docker image
      run: |
        docker build --target test -t amplicon-prime:test .
        docker run --rm amplicon-prime:test

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions