Skip to content

Commit

Permalink
First article
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Havlicek authored and princess-entrapta committed Oct 27, 2023
0 parents commit 60e113f
Show file tree
Hide file tree
Showing 43 changed files with 923 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/hugo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Sample workflow for building and deploying a Hugo site to GitHub Pages
name: Deploy Hugo site to Pages

on:
# Runs on pushes targeting the default branch
push:
branches:
- main

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

# Default to bash
defaults:
run:
shell: bash

jobs:
# Build job
build:
runs-on: ubuntu-latest
env:
HUGO_VERSION: 0.115.4
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Setup Pages
id: pages
uses: actions/configure-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: ./public

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "themes/ananke"]
path = themes/ananke
url = https://github.com/theNewDynamic/gohugo-theme-ananke.git
[submodule "themes/hermit"]
path = themes/hermit
url = https://github.com/Track3/hermit.git
Empty file added .hugo_build.lock
Empty file.
6 changes: 6 additions & 0 deletions archetypes/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---

80 changes: 80 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
baseURL = "https://example.com"
languageCode = "en-us"
defaultContentLanguage = "en"
title = "Hugo Hermit"
theme = "hermit"
# enableGitInfo = true
pygmentsCodefences = true
pygmentsUseClasses = true
# hasCJKLanguage = true # If Chinese/Japanese/Korean is your main content language, enable this to make wordCount works right.
rssLimit = 10 # Maximum number of items in the RSS feed.
copyright = "This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License." # This message is only used by the RSS template.
enableEmoji = true # Shorthand emojis in content files - https://gohugo.io/functions/emojify/
# googleAnalytics = "UA-123-45"
# disqusShortname = "yourdiscussshortname"

[author]
name = "John Doe"

[blackfriday]
# hrefTargetBlank = true
# noreferrerLinks = true
# nofollowLinks = true

[taxonomies]
tag = "tags"
# Categories are disabled by default.

[params]
dateform = "Jan 2, 2006"
dateformShort = "Jan 2"
dateformNum = "2006-01-02"
dateformNumTime = "2006-01-02 15:04 -0700"

# Metadata mostly used in document's head
# description = ""
# images = [""]
themeColor = "#494f5c"

homeSubtitle = "A minimal and fast theme for Hugo."
footerCopyright = ' &#183; <a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank" rel="noopener">CC BY-NC 4.0</a>'
# bgImg = "" # Homepage background-image URL

# Prefix of link to the git commit detail page. GitInfo must be enabled.
# gitUrl = "https://github.com/username/repository/commit/"

# Toggling this option needs to rebuild SCSS, requires Hugo extended version
justifyContent = false # Set "text-align: justify" to `.content`.

relatedPosts = false # Add a related content section to all single posts page

code_copy_button = true # Turn on/off the code-copy-button for code-fields

# Add custom css
# customCSS = ["css/foo.css", "css/bar.css"]

# Social Icons
# Check https://github.com/Track3/hermit#social-icons for more info.
[[params.social]]
name = "twitter"
url = "https://twitter.com/"

[[params.social]]
name = "instagram"
url = "https://instagram.com/"

[[params.social]]
name = "github"
url = "https://github.com/"

[menu]

[[menu.main]]
name = "Posts"
url = "posts/"
weight = 10

[[menu.main]]
name = "About"
url = "about-hugo/"
weight = 20
6 changes: 6 additions & 0 deletions content/about-me.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
+++
title = "About Me"
date = "2023-10-25"
+++

Coming soon
108 changes: 108 additions & 0 deletions content/posts/build-rust-dockerfile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
title: "Dockerfile for small Rust images (with dependency build caching)"
date: 2023-10-25T12:56:00+02:00
draft: false
---

# Introduction

After reading multiple tutorials for building docker images and optimize them, I compiled an optimized Dockerfile that can:
- Have final images that are small, in the 50MB range
- Benefit from docker caching, allowing to have build times under 10s if you don't change dependencies

We will assume here you start with a project `my_app` you already have or have created with `cargo new`.

# Setting up

We use this docker file. This technique is called a multi-stage build. When docker builds with `docker build` or `docker compose build`, it creates two successive images:
- One that serve to create the binary
- One that will execute the binary without the build environment

The second one can be minimized by removing unecessary system components that are already bundled in the produced binary.


```Dockerfile
## BUILDER IMAGE
FROM rust:1.73 as builder

WORKDIR /usr/app
RUN rustup target add x86_64-unknown-linux-musl
RUN apt update && apt install -y musl-tools musl-dev
RUN update-ca-certificates

WORKDIR /usr/app/api_gateway

RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid 10001 \
userland

COPY ./Cargo.toml ./Cargo.toml
RUN mkdir src && echo "fn main(){}" > ./src/main.rs
# Build the dependencies. This is the longest part and we don´t want
# to repeat it if there is no dependency change,
# which is why there is no copy or volume for sources at this point
RUN cargo build --target x86_64-unknown-linux-musl --release
COPY ./src ./src

# 5. Build for release.
RUN cargo build --target x86_64-unknown-linux-musl --release
## EXECUTOR
FROM alpine
# You can include a healthcheck here, for demons and network-based services.
# For http checks, don't forget curl is not readily available on alpine

# HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "curl --fail http://localhost:8000/health" ]
# RUN apk add curl
RUN apk add libc6-compat

WORKDIR /opt
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /usr/app/my_app/target/x86_64-unknown-linux-musl/release/my_app ./

RUN chown userland:userland ./my_app

CMD ["/usr/app/my_app"]
```

Alpine doesn't natively provide glibc or libssl. For this reason, we will need some additions in the Cargo.toml file.

At end of file, below your dependencies, add the following section:

```ini
[target.'cfg(all(target_env = "musl", target_pointer_width = "64"))'.dependencies.jemallocator]
version = "0.3"
```

You can learn more about what is jemalloc [here](https://jemalloc.net/)

If you use things that are dependent of ssl, such as reqwest, you might also need to tweak the dependency to include `rust-tls`:

```ini
reqwest = {version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
```
## Running

Try to `docker build` your image. If it is successful, try to `docker run` the obtained container. It should execute your binary.

You notice your first `docker build` was probably long, several minutes long perhaps.

Try to modify your sources, then `docker build` again. You should notice the build to be significantly faster.

Use `docker images` and inspect image size. Smaller images are faster to push and pull over network, they also cost less to store.

# Conclusion

We learned to make a multi-stage build to produce small docker images for Rust, and use the best of docker caching to avoid a costy rebuild
of dependencies at every source change.


## Thanks to / further reading

- [Multi stage build for docker](https://docs.docker.com/build/building/multi-stage/)
- [Notes from cargo team on dependency caching](https://hackmd.io/@kobzol/S17NS71bh)
10 changes: 10 additions & 0 deletions content/posts/new.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: "New"
date: 2023-10-25T17:39:11+02:00
draft: true
toc: false
images:
tags:
- untagged
---

72 changes: 72 additions & 0 deletions hugo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
baseURL = "https://example.com"
languageCode = "en-us"
defaultContentLanguage = "en"
title = "Diane M's blog"
theme = "hermit"
# enableGitInfo = true
pygmentsCodefences = true
pygmentsUseClasses = true
# hasCJKLanguage = true # If Chinese/Japanese/Korean is your main content language, enable this to make wordCount works right.
rssLimit = 10 # Maximum number of items in the RSS feed.
copyright = "This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License." # This message is only used by the RSS template.
enableEmoji = true # Shorthand emojis in content files - https://gohugo.io/functions/emojify/
# googleAnalytics = "UA-123-45"
# disqusShortname = "yourdiscussshortname"

[author]
name = "Diane M."

[blackfriday]
# hrefTargetBlank = true
# noreferrerLinks = true
# nofollowLinks = true

[taxonomies]
tag = "tags"
# Categories are disabled by default.

[params]
dateform = "Jan 2, 2006"
dateformShort = "Jan 2"
dateformNum = "2006-01-02"
dateformNumTime = "2006-01-02 15:04 -0700"

# Metadata mostly used in document's head
# description = ""
# images = [""]
themeColor = "#494f5c"

homeSubtitle = "Personal blog"
footerCopyright = ' &#183; <a href="https://creativecommons.org/publicdomain/zero/1.0/" target="_blank" rel="noopener">CC0 License</a>'
# bgImg = "" # Homepage background-image URL

# Prefix of link to the git commit detail page. GitInfo must be enabled.
# gitUrl = "https://github.com/username/repository/commit/"

# Toggling this option needs to rebuild SCSS, requires Hugo extended version
justifyContent = false # Set "text-align: justify" to `.content`.

relatedPosts = false # Add a related content section to all single posts page

code_copy_button = true # Turn on/off the code-copy-button for code-fields

# Add custom css
# customCSS = ["css/foo.css", "css/bar.css"]

# Social Icons
# Check https://github.com/Track3/hermit#social-icons for more info.
[[params.social]]
name = "github"
url = "https://github.com/princess-entrapta"

[menu]

[[menu.main]]
name = "Posts"
url = "posts/"
weight = 10

[[menu.main]]
name = "About"
url = "about-hugo/"
weight = 20
2 changes: 2 additions & 0 deletions public/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!doctype html><html lang=en-us><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><meta http-equiv=x-ua-compatible content="ie=edge"><meta name=theme-color content="#494f5c"><meta name=msapplication-TileColor content="#494f5c"><meta itemprop=name content="404 Page not found"><meta itemprop=description content><meta property="og:title" content="404 Page not found"><meta property="og:description" content><meta property="og:type" content="website"><meta property="og:url" content="https://princess-entrapta.github.io/blog/404.html"><meta name=twitter:card content="summary"><meta name=twitter:title content="404 Page not found"><meta name=twitter:description content><link rel=apple-touch-icon sizes=180x180 href=/blog/apple-touch-icon.png><link rel=icon type=image/png sizes=32x32 href=/blog/favicon-32x32.png><link rel=icon type=image/png sizes=16x16 href=/blog/favicon-16x16.png><link rel=manifest href=/blog/site.webmanifest><link rel=mask-icon href=/blog/safari-pinned-tab.svg color><link rel="shortcut icon" href=/blog/favicon.ico><title>404 Page not found</title><link rel=stylesheet href=https://princess-entrapta.github.io/blog/css/style.min.037b6ee8f8c1baab6a3d0a9da11c3ff18a7552471f16c59fd98538d5ce99208b.css integrity="sha256-A3tu6PjBuqtqPQqdoRw/8Yp1UkcfFsWf2YU41c6ZIIs=" crossorigin=anonymous></head><body id=page><div id=spotlight class="error-404 animated fadeIn"><p class=img-404><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 167.8 163.4" fill="currentcolor"><title>404-lighthouse</title><path d="M83 27.5c.5-8.4 12.5-8.4 13 0 .2 3.2 5.2 3.2 5 0C100.7 21.3 96 16 89.5 16S78.3 21.3 78 27.5c-.2 3.2 4.8 3.2 5 0z" transform="translate(-6.6 -6.6)"/><path d="M92 18V9c0-3.2-5-3.2-5 0v9c0 3.2 5 3.2 5 0z" transform="translate(-6.6 -6.6)"/><path d="M78 44.5l-7.9 86.7L69 143.5c-.3 3.2 4.7 3.2 5 0l7.9-86.7L83 44.5c.3-3.2-4.7-3.2-5 0z" transform="translate(-6.6 -6.6)"/><path d="M96 44.5l7.9 86.7 1.1 12.3c.3 3.2 5.3 3.2 5 0l-7.9-86.7L101 44.5c-.3-3.2-5.3-3.2-5 0z" transform="translate(-6.6 -6.6)"/><path d="M88.5 26.5v18a1 1 0 002 0v-18a1 1 0 00-2 0z" transform="translate(-6.6 -6.6)"/><path d="M79.1 69.6l21.2-12.2a1.5 1.5.0 00-1.5-2.6L77.6 67a1.5 1.5.0 001.5 2.6z" transform="translate(-6.6 -6.6)"/><path d="M76.4 99.2 102.7 84a1.5 1.5.0 00-1.5-2.6L74.9 96.6a1.5 1.5.0 001.5 2.6z" transform="translate(-6.6 -6.6)"/><path d="M73.7 128.7l31.4-18.1a1.5 1.5.0 00-1.5-2.6L72.2 126.1a1.5 1.5.0 001.5 2.6z" transform="translate(-6.6 -6.6)"/><path d="M98.5 42h-18L83 44.5v-18L80.5 29h18L96 26.5v18c0 3.2 5 3.2 5 0v-18A2.5 2.5.0 0098.5 24h-18A2.5 2.5.0 0078 26.5v18A2.5 2.5.0 0080.5 47h18c3.2.0 3.2-5 0-5z" transform="translate(-6.6 -6.6)"/><path d="M172 165c-5.8-.3-9.5-4.7-15.8-3.8-2.6.4-4.4 1.6-6.7 2.7s-6.9 1.3-10.2-.5-9.5-3.2-14.3-1c-3.3 1.5-5.6 3.3-9.5 2.4-2.4-.5-4.3-2.3-6.7-3.1a15.5 15.5.0 00-8.3-.3c-2.5.6-4.3 2.2-6.7 3.1-6.2 2.2-10.8-3.5-16.9-3.5s-10.7 5.6-17 3.5c-2.3-.8-4.2-2.5-6.7-3.1a15.4 15.4.0 00-8.3.3c-3.1 1-5.4 3.3-8.9 3.3s-5.8-2.2-8.9-3.3a15.4 15.4.0 00-8.8-.2c-3.4 1-5.7 3.3-9.5 3.5s-3.2 5.2.0 5c6-.3 10.9-5.5 17-3.5 2.4.8 4.2 2.5 6.7 3.1a15.4 15.4.0 008.3-.3c2.3-.8 4.2-2.5 6.7-3.1s6.3.9 9.5 2.4c4.8 2.3 9.8 1.5 14.3-1s6.7-2.2 10.2-.5 4.1 2.3 6.7 2.7a14.9 14.9.0 007.9-1c2.7-1.2 4.8-2.9 7.9-2.9s5.2 1.7 7.9 2.9a14.9 14.9.0 007.9 1c2.6-.4 4.4-1.6 6.7-2.7s6.9-1.3 10.2.5a15.9 15.9.0 0016.1.0c7.3-3.9 11.9 2 19.1 2.3 3.2.2 3.2-4.8.0-5z" transform="translate(-6.6 -6.6)"/><path d="M46.3 165.8l9.6-9.3c4.9-4.6 9.7-11.1 17.2-9.2 4.9 1.2 9.2 5.5 13 8.5s8 6.5 12.1 9.7c2.6 2 5-2.4 2.5-4.3-5-3.8-9.7-7.9-14.7-11.7s-8.7-7-14.6-7.6-11.2 3.6-15.9 8S47 158 42.7 162.2c-2.3 2.3 1.2 5.8 3.5 3.5z" transform="translate(-6.6 -6.6)"/><path d="M84.8 152.8c8.3-3.7 16.7-8.3 26.1-5.6s15.5 9 19.4 16.6c1.5 2.9 5.8.3 4.3-2.5-4.5-8.7-12.9-16.2-22.4-18.9s-20.3 1.7-29.9 6.1c-2.9 1.3-.4 5.6 2.5 4.3z" transform="translate(-6.6 -6.6)"/><g class="animated flash infinite slower"><path d="M62.5 34h-23a1.5 1.5.0 000 3h23a1.5 1.5.0 000-3z" transform="translate(-6.6 -6.6)"/><path d="M63.3 25.2l-18-9c-1.7-.9-3.2 1.7-1.5 2.6l18 9c1.7.9 3.2-1.7 1.5-2.6z" transform="translate(-6.6 -6.6)"/><path d="M61.7 43.2l-18 9c-1.7.9-.2 3.5 1.5 2.6l18-9c1.7-.9.2-3.5-1.5-2.6z" transform="translate(-6.6 -6.6)"/><path d="M116.5 37h23a1.5 1.5.0 000-3h-23a1.5 1.5.0 000 3z" transform="translate(-6.6 -6.6)"/><path d="M117.3 27.8l18-9c1.7-.9.2-3.5-1.5-2.6l-18 9c-1.7.9-.2 3.5 1.5 2.6z" transform="translate(-6.6 -6.6)"/><path d="M115.7 45.8l18 9c1.7.9 3.2-1.7 1.5-2.6l-18-9c-1.7-.9-3.2 1.7-1.5 2.6z" transform="translate(-6.6 -6.6)"/></g></svg></p><div class=banner-404><h1>404</h1><p>Oops, page not found…</p><p class=btn-404><a href=https://princess-entrapta.github.io/blog/><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-home"><path d="M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg>Home</a>
<a href=https://princess-entrapta.github.io/blog/posts><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-archive"><polyline points="21 8 21 21 3 21 3 8"/><rect x="1" y="3" width="22" height="5"/><line x1="10" y1="12" x2="14" y2="12"/></svg>Archives</a></p></div></div><script src=https://princess-entrapta.github.io/blog/js/bundle.min.580988ed2982bcbb74a1773c7abea97b43e4c43b9324e10cda0813ec6ec4bb67.js integrity="sha256-WAmI7SmCvLt0oXc8er6pe0PkxDuTJOEM2ggT7G7Eu2c=" crossorigin=anonymous></script></body></html>
Loading

0 comments on commit 60e113f

Please sign in to comment.