Skip to content

Commit 60aac1a

Browse files
authored
Merge pull request #49 from arghyadipchak/master
Automated docker build for DockerHub + updated cargo.toml
2 parents 7cd136c + afa3c51 commit 60aac1a

File tree

3 files changed

+87
-26
lines changed

3 files changed

+87
-26
lines changed

.github/workflows/docker.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
tags:
8+
- "v*"
9+
pull_request:
10+
branches:
11+
- "master"
12+
13+
jobs:
14+
docker_image:
15+
name: Build & push docker image to DockerHub
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v3
20+
21+
- name: Docker meta
22+
id: meta
23+
uses: docker/metadata-action@v4
24+
with:
25+
images: ${{ secrets.DOCKERHUB_REPO }}
26+
tags: |
27+
type=semver,pattern={{version}}
28+
type=semver,pattern={{major}}.{{minor}}
29+
type=semver,pattern={{major}}
30+
31+
- name: Setup QEMU
32+
uses: docker/setup-qemu-action@v2
33+
34+
- name: Setup Docker Buildx
35+
uses: docker/setup-buildx-action@v2
36+
37+
- name: Login DockerHub
38+
if: github.event_name != 'pull_request'
39+
uses: docker/login-action@v2
40+
with:
41+
username: ${{ secrets.DOCKERHUB_USERNAME }}
42+
password: ${{ secrets.DOCKERHUB_TOKEN }}
43+
44+
- name: Build & push
45+
uses: docker/build-push-action@v3
46+
with:
47+
platforms: linux/amd64, linux/arm64
48+
push: ${{ github.ref_type == 'tag' }}
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}

Cargo.toml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
2-
name="microbin"
3-
version="1.1.0"
4-
edition="2021"
2+
name = "microbin"
3+
version = "1.1.0"
4+
edition = "2021"
55
authors = ["Daniel Szabo <daniel.szabo99@outlook.com>"]
66
license = "BSD-3-Clause"
77
description = "Simple, performant, configurable, entirely self-contained Pastebin and URL shortener."
@@ -11,20 +11,18 @@ repository = "https://github.com/szabodanika/microbin"
1111
keywords = ["pastebin", "pastabin", "microbin", "actix", "selfhosted"]
1212
categories = ["pastebins"]
1313

14-
15-
1614
[dependencies]
17-
actix-web="4"
18-
actix-files="0.6.0"
19-
serde={ version = "1.0", features = ["derive"] }
15+
actix-web = "4"
16+
actix-files = "0.6.0"
17+
serde = { version = "1.0", features = ["derive"] }
2018
serde_json = "1.0.80"
2119
bytesize = { version = "1.1", features = ["serde"] }
22-
askama="0.10"
23-
askama-filters={ version = "0.1.3", features = ["chrono"] }
24-
chrono="0.4.19"
25-
rand="0.8.5"
26-
linkify="0.8.1"
27-
clap={ version = "3.1.12", features = ["derive", "env"] }
20+
askama = "0.10"
21+
askama-filters = { version = "0.1.3", features = ["chrono"] }
22+
chrono = "0.4.19"
23+
rand = "0.8.5"
24+
linkify = "0.8.1"
25+
clap = { version = "3.1.12", features = ["derive", "env"] }
2826
actix-multipart = "0.4.0"
2927
futures = "0.3"
3028
sanitize-filename = "0.3.0"
@@ -34,3 +32,6 @@ actix-web-httpauth = "0.6.0"
3432
lazy_static = "1.4.0"
3533
syntect = "5.0"
3634

35+
[profile.release]
36+
lto = true
37+
strip = true

Dockerfile

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1-
# latest rust will be used to build the binary
2-
FROM rust:latest as builder
1+
FROM rust:latest as build
32

4-
# the temporary directory where we build
5-
WORKDIR /usr/src/microbin
3+
WORKDIR /app
64

7-
# copy sources to /usr/src/microbin on the temporary container
85
COPY . .
96

10-
# run release build
11-
RUN cargo build --release
7+
RUN \
8+
DEBIAN_FRONTEND=noninteractive \
9+
apt-get update &&\
10+
apt-get -y install ca-certificates tzdata &&\
11+
cargo build --release
1212

1313
# https://hub.docker.com/r/bitnami/minideb
1414
FROM bitnami/minideb:latest
1515

16-
# microbin will be in /usr/local/bin/microbin/
17-
WORKDIR /usr/local/bin
16+
# microbin will be in /app
17+
WORKDIR /app
18+
19+
# copy time zone info
20+
COPY --from=build \
21+
/usr/share/zoneinfo \
22+
/usr/share/zoneinfo
23+
24+
COPY --from=build \
25+
/etc/ssl/certs/ca-certificates.crt \
26+
/etc/ssl/certs/ca-certificates.crt
1827

1928
# copy built exacutable
20-
COPY --from=builder /usr/src/microbin/target/release/microbin /usr/local/bin/microbin
29+
COPY --from=build \
30+
/app/target/release/microbin \
31+
/usr/bin/microbin
2132

22-
# run the binary
23-
CMD ["microbin"]
33+
ENTRYPOINT ["microbin"]

0 commit comments

Comments
 (0)