Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Setup #1

Merged
merged 9 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: Bug Report
about: Create a report to help us improve
title: ""
labels: ""
assignees: ""
---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**

- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Feature Request
about: Suggest an idea for this project
title: ""
labels: ""
assignees: ""
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
50 changes: 50 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!--- Provide a short summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->

## Testing

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->

## Dependencies Added:

<!--- Detail the dependencies added for this solution -->

## Dependencies Removed:

<!--- Detail the dependencies removed for this solution -->

## Other Changes:

<!--- Detail any non-related / add-on changes made to the codebase -->

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
<!--- DELETE OR COMMENT OUT THE OTHER CHOICES -->

- [ ] New feature (non-breaking change which adds functionality)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Optimization (non-breaking change which improves performance)
- [ ] Documentation (non-breaking change which improves documentation)
- [ ] Refactoring / Cleanup (non-breaking change which does not add functionality or fix issues)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->

- [ ] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly (or no changes needed).
- [ ] I have added tests to cover my changes (or no new test are needed).
- [ ] All new and existing tests are passing.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# GitHub Action runners come pre-installed with Cargo 1.76.0 (latest)

name: CI
on:
pull_request:
branches: ["main"]
workflow_dispatch:

jobs:
Build:
runs-on: ubuntu-latest

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

- name: Format
run: make format

- name: Test
run: make test

- name: Deploy
run: |
echo "Deploying..."
# make build
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "rust_cli_template"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.1", features = ["cargo", "derive"] }
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# syntax=docker/dockerfile:1

###############################################################
# Builder
###############################################################
FROM rust:1.76 as build

WORKDIR /app

# Copy dependencies
COPY . .

# Build binary
RUN cargo build --release


###############################################################
# Final
###############################################################

# Copy artifacts to a clean image
FROM debian:stable-slim

COPY --from=build /app/target/release/rust_cli_template .

ENTRYPOINT [ "./rust_cli_template" ]
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
build:
cargo build --release

clean:
cargo clean

doc:
cargo doc --no-deps --open

lint:
cargo clippy

format:
cargo fmt

test:
cargo test
173 changes: 173 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#! /bin/bash
#
# This script sets up a local development environment on an Ubuntu 20.04/22.04 machine
# to work with Rust (cargo 1.76.0) projects.
#
# Targets:
# - cargo 1.76.0
# - Docker 24.0.6
#
# Requirements:
# - Ubuntu 20.04/22.04
#

# -----------------------------------------------------------------------------------------------------------
# 0) Config: here we'll set up default variables.
# -----------------------------------------------------------------------------------------------------------

# Pull the current machine's distro for GPG key targeting
readonly DISTRO="$(lsb_release -d | awk -F ' ' '{print tolower($2)}')"


# -----------------------------------------------------------------------------------------------------------
# 1) Base Requirements: this will ensure that you have some base requirements installed.
# -----------------------------------------------------------------------------------------------------------

# Check if ca-certificates is in the apt-cache
if ( apt-cache show ca-certificates > /dev/null ); then
echo 'ca-certificates is already cached 🟢'
else
sudo apt update
fi

# Ensure ca-certificates package is installed on the machine
if ( which update-ca-certificates > /dev/null ); then
echo 'ca-certificates is already installed 🟢'
else
echo 'Installing ca-certificates 📜'
sudo apt-get install -y ca-certificates
fi

# Check if curl is in the apt-cache
if ( apt-cache show curl > /dev/null ); then
echo 'curl is already cached 🟢'
else
sudo apt update
fi

# Ensure curl is installed on the machine
if ( which curl > /dev/null ); then
echo 'curl is already installed 🟢'
else
echo 'Installing curl 🌀'
sudo apt install -y curl
fi

# Check if make is in the apt-cache
if ( apt-cache show make > /dev/null ); then
echo 'make is already cached 🟢'
else
sudo apt update
fi

# Ensure make is installed on the machine
if ( which make > /dev/null ); then
echo 'make is already installed 🟢'
else
echo 'Installing make 🔧'
sudo apt install -y make
fi

# Check if gnupg is in the apt-cache
if ( apt-cache show gpg > /dev/null ); then
echo 'gnupg is already cached 🟢'
else
sudo apt update
fi

# Ensure gnupg is installed on the machine
if ( which gpg > /dev/null ); then
echo 'make is already installed 🟢'
else
echo 'Installing gnugp 🔧'
sudo apt install -y gnupg
fi


# -----------------------------------------------------------------------------------------------------------
# 2) Rust Install: here we'll install and configure Cargo.
# -----------------------------------------------------------------------------------------------------------

# Install Cargo
if ( which cargo > /dev/null ); then
echo "Cargo is already installed 🟢"
else
echo "Installing Rust 🦀"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y
source ~/.bashrc
fi

# Verify installation of Cargo
if ( cargo version > /dev/null ); then
echo "$(cargo version) 🦀 🚀"
else
echo "Cargo was not installed successfully 🔴"
fi


# -----------------------------------------------------------------------------------------------------------
# 3) Docker Install: here we'll install Docker
# -----------------------------------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------------------------------
# 3.1) Set up the repository: Before you install Docker Engine for the first time on a new host machine,
# you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.
# -----------------------------------------------------------------------------------------------------------

# Add Docker’s official GPG key
if [[ -f /etc/apt/keyrings/docker.gpg ]]; then
echo 'Docker GPG Key already installed at /etc/apt/keyrings/docker.gpg 🟢'
else
echo 'Installing Docker GPG Key at /etc/apt/keyrings/docker.gpg 🔧'

# Create the /etc/apt/keyrings directory with appropriate permissions
sudo install -m 0755 -d /etc/apt/keyrings

# Download the GPG key from Docker
curl -fsSL https://download.docker.com/linux/${DISTRO}/gpg \
| sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

sudo chmod a+r /etc/apt/keyrings/docker.gpg
fi

# Set up the repository
if [[ -f /etc/apt/sources.list.d/docker.list ]]; then
echo 'docker.list repository already exists at /etc/apt/sources.list.d/docker.list 🟢'
else
echo 'Installing docker.list repository at /etc/apt/sources.list.d/docker.list 🔧'
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/$DISTRO \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" \
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
fi

# -----------------------------------------------------------------------------------------------------------
# 3.2) Install Docker Engine
# -----------------------------------------------------------------------------------------------------------

# Check if docker-ce is in the apt-cache
if ( apt-cache show docker-ce > /dev/null ); then
echo 'docker-ce is already cached 🟢'
else
sudo apt update
fi

# Install Docker Engine, containerd, and Docker Compose
if ( docker --version > /dev/null ); then
echo 'Docker is already installed 🟢'
echo "Using $(docker --version)"
else
echo 'Installing Docker 🐳'

# Installs
sudo apt-get install -y docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin

# Verify that the Docker Engine installation is successful by running the hello-world image
sudo docker run --rm hello-world
fi
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}