Skip to content

Commit

Permalink
Dockerfile ubuntu ready, compose too. commiting trunk as well
Browse files Browse the repository at this point in the history
  • Loading branch information
zMynxx committed Feb 26, 2024
1 parent e45201d commit 2c29285
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 29 deletions.
9 changes: 9 additions & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*out
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
tmp
4 changes: 4 additions & 0 deletions .trunk/configs/.hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Following source doesn't work in most setups
ignored:
- SC1090
- SC1091
10 changes: 10 additions & 0 deletions .trunk/configs/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Autoformatter friendly markdownlint config (all formatting rules disabled)
default: true
blank_lines: false
bullet: false
html: false
indentation: false
line_length: false
spaces: false
url: false
whitespace: false
7 changes: 7 additions & 0 deletions .trunk/configs/.yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules:
quoted-strings:
required: only-when-needed
extra-allowed: ["{|}"]
key-duplicates: {}
octal-values:
forbid-implicit-octal: true
34 changes: 34 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.20.1
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
plugins:
sources:
- id: trunk
ref: v1.4.3
uri: https://github.com/trunk-io/plugins
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
runtimes:
enabled:
- node@18.12.1
- python@3.10.8
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
lint:
enabled:
- checkov@3.2.24
- git-diff-check
- hadolint@2.12.0
- markdownlint@0.39.0
- prettier@3.2.5
- terrascan@1.18.11
- trivy@0.49.1
- trufflehog@3.68.0
- yamllint@1.35.1
actions:
enabled:
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
- trunk-upgrade-available
91 changes: 91 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# syntax=docker/dockerfile:1

# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/go/dockerfile-reference/

# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7

################################################################################
# Pick a base image to serve as the foundation for the other build stages in
# this file.
#
# For illustrative purposes, the following FROM command
# is using the alpine image (see https://hub.docker.com/_/alpine).
# By specifying the "latest" tag, it will also use whatever happens to be the
# most recent version of that image when you build your Dockerfile.
# If reproducability is important, consider using a versioned tag
# (e.g., alpine:3.17.2) or SHA (e.g., alpine@sha256:c41ab5c992deb4fe7e5da09f67a8804a46bd0592bfdf0b1847dde0e0889d2bff).
FROM alpine:3.19.1 as base

RUN apk --no-cache add \
coreutils \
gcc \
gcovr \
valgrind \
libc-dev \
gdb

RUN gem install ceedling

################################################################################
# Create a stage for building/compiling the application.
#
# The following commands will leverage the "base" stage above to generate
# a "hello world" script and make it executable, but for a real application, you
# would issue a RUN command for your application's build process to generate the
# executable. For language-specific examples, take a look at the Dockerfiles in
# the Awesome Compose repository: https://github.com/docker/awesome-compose
FROM base as build

# Install all necessary build tools and dependencies.
RUN apk update
RUN apk --update-cache add \
bash \
vim \
wget

# Manually install ruby 3.1.4 to avoid issues with the ceedling version 0.31.1 'exist' issue which is deprecated in the latest version of ruby (>3.2)
RUN wget https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.4.tar.gz
RUN tar -xzvf ruby-3.1.4.tar.gz
RUN cd ruby-3.1.4 && ./configure && make && make Install

# Install ceedling
RUN gen update && \
gem install ceedling


RUN echo -e '#!/bin/sh\n\
echo Hello world from $(whoami)! In order to get your application running in a container, take a look at the comments in the Dockerfile to get started.'\
> /bin/hello.sh
RUN chmod +x /bin/hello.sh

################################################################################
# Create a final stage for running your application.
#
# The following commands copy the output from the "build" stage above and tell
# the container runtime to execute it when the image is run. Ideally this stage
# contains the minimal runtime dependencies for the application as to produce
# the smallest image possible. This often means using a different and smaller
# image than the one used for building the application, but for illustrative
# purposes the "base" image is used here.
FROM base AS final

# Create a non-privileged user that the app will run under.
# See https://docs.docker.com/go/dockerfile-user-best-practices/
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
appuser
USER appuser

# Copy the executable from the "build" stage.
COPY --from=build /bin/hello.sh /bin/

# What the container should run when it is started.
ENTRYPOINT [ "/bin/hello.sh" ]
47 changes: 47 additions & 0 deletions Dockerfile.rbenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM alpine:3.19.1 as final
MAINTAINER lior.dux@develeap.com

# Install all necessary build tools and dependencies.
RUN apk --update-cache add \
openssl \
openssl-dev \
perl \
make \
gcc \
gcompat \

RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub &&\
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r1/glibc-2.35-r1.apk &&\
apk add glibc-2.35-r1.apk

coreutils \
gcovr \
valgrind \
libc-dev \
gdb \

# Additions to the base image
RUN apk --update-cache add \
bash \
git \
wget \
curl \
vim \


#&& rm -rf /var/cache/apk/*

# Install rbenv-build
RUN wget -q https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer -O- | bash
RUN echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bash_profile

# rbenv
ENV RBENV_ROOT /root/.rbenv/bin/rbenv
ENV RUBY_VERSION 3.0.6
#ENV CONFIGURE_OPTS --disable-install-doc


RUN rbenv install $RUBY_VERSION &&\
rbenv global $RUBY_VERSION

RUN gem install bundler
38 changes: 18 additions & 20 deletions Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,20 @@ RUN apt-get clean &&\
# Install rbenv-build
#RUN curl --fail --silent --show-error --location https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
RUN curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
ENV PATH="$PATH:/root/.rbenv/bin:/root/.rbenv/shims"

# Validate rbenv using rbev-doctor
#RUN curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor | bash
RUN curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor | bash
RUN echo 'eval "$(~/.rbenv/bin/rbenv init -)"' >> /etc/profile.d/rbenv.sh

# Set rbenv version desired on build time
# Install rbenv and set the desired version
ARG RBENV_VERSION=3.0.6
ENV RBENV_VERSION $RBENV_VERSION

# Install rbenv and set the desired version
RUN echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc
ENV PATH="$PATH:/root/.rbenv/bin:/root/.rbenv/shims"
RUN /root/.rbenv/bin/rbenv install $RBENV_VERSION &&\
/root/.rbenv/bin/rbenv global $RBENV_VERSION
RUN rbenv install $RBENV_VERSION &&\
rbenv global $RBENV_VERSION

# Install ceedling, cmock and unity
RUN /root/.rbenv/shims/gem install ceedling
RUN gem install ceedling

################################################################################
# Create a final stage for running your application.
Expand All @@ -64,15 +62,15 @@ RUN /root/.rbenv/shims/gem install ceedling
#
# # Create a non-privileged user that the app will run under.
# # See https://docs.docker.com/go/dockerfile-user-best-practices/
ARG UID=10001
ARG USER=ubuntu
ENV USER $USER
RUN useradd \
--home "/nonexistent" \
--shell "/bin/bash" \
--create-home \
--uid "${UID}" \
--groups sudo \
$USER
USER $USER
# ARG UID=10001
# ARG USER=ubuntu
# ENV USER $USER
# RUN useradd \
# --uid "${UID}" \
# --create-home \
# --shell "/bin/bash" \
# --groups sudo \
# $USER
# USER $USER
WORKDIR /project
CMD bash
17 changes: 17 additions & 0 deletions README.Docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### Building and running your application

When you're ready, start your application by running:
`docker compose up --build`.

### Deploying your application to the cloud

First, build your image, e.g.: `docker build -t myapp .`.
If your cloud uses a different CPU architecture than your development
machine (e.g., you are on a Mac M1 and your cloud provider is amd64),
you'll want to build the image for that platform, e.g.:
`docker build --platform=linux/amd64 -t myapp .`.

Then, push it to your registry, e.g. `docker push myregistry.com/myapp`.

Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/)
docs for more detail on building and pushing.
28 changes: 28 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Docker compose reference guide at
# https://docs.docker.com/go/compose-spec-reference/

# Here the instructions define your application as a service called "app".
# This service is built from the Dockerfile in the current directory.
# You can add other services your application may depend on here, such as a
# database or a cache. For examples, see the Awesome Compose repository:
# https://github.com/docker/awesome-compose
services:
app:
image: druxx/ubuntu-ceedling:22.04-v0.31.1
platform: linux/amd64
build:
context: .
dockerfile: Dockerfile.ubuntu
tty: true
stdin_open: true
command: /bin/bash
volumes:
- ./demo:/project
restart: unless-stopped

# If your application exposes a port, uncomment the following lines and change
# the port numbers as needed. The first number is the host port and the second
# is the port inside the container.
# ports:
# - 8080:8080
25 changes: 16 additions & 9 deletions demo/project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

# Notes:
# Sample project C code is not presently written to produce a release artifact.
# As such, release build options are disabled.
Expand Down Expand Up @@ -60,11 +59,11 @@
- :ignore
- :callback
:treat_as:
uint8: HEX8
uint16: HEX16
uint32: UINT32
int8: INT8
bool: UINT8
uint8: HEX8
uint16: HEX16
uint32: UINT32
int8: INT8
bool: UINT8

# Add -gcov to the plugins list to make sure of the gcov plugin
# You will need to have gcov and gcovr both installed to make it work.
Expand All @@ -80,7 +79,7 @@
# Ceedling defaults to using gcc for compiling, linking, etc.
# As [:tools] is blank, gcc will be used (so long as it's in your system path)
# See documentation to configure a given toolchain for use
#
#
# :tools:
# :pre_test_fixture_execute:
# :executable: valgrind
Expand All @@ -92,6 +91,15 @@
# - --error-exitcode=10
# - ${1}

# Add debug symbols
:tools_test_compiler:
:arguments:
- -g

:tools_test_linker:
:arguments:
- -g

# LIBRARIES
# These libraries are automatically injected into the build process. Those specified as
# common will be used in all types of builds. Otherwise, libraries can be injected in just
Expand All @@ -100,7 +108,7 @@
:placement: :end
:flag: "-l${1}"
:path_flag: "-L ${1}"
:system: [] # for example, you might list 'm' to grab the math library
:system: [] # for example, you might list 'm' to grab the math library
:test: []
:release: []

Expand All @@ -111,4 +119,3 @@
- stdout_pretty_tests_report
- module_generator
# - command_hooks
...

0 comments on commit 2c29285

Please sign in to comment.