Skip to content

Commit 8e97828

Browse files
committed
ci: add docker image build
1 parent eed2b71 commit 8e97828

File tree

5 files changed

+157
-28
lines changed

5 files changed

+157
-28
lines changed

.github/workflows/docker-publish.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Docker
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
push:
10+
branches: [ main ]
11+
# Publish semver tags as releases.
12+
tags: [ 'v*.*.*' ]
13+
pull_request:
14+
branches: [ main ]
15+
16+
env:
17+
# Use docker.io for Docker Hub if empty
18+
REGISTRY: ghcr.io
19+
# github.repository as <account>/<repo>
20+
IMAGE_NAME: ${{ github.repository }}
21+
22+
23+
jobs:
24+
build:
25+
26+
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read
29+
packages: write
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v2
34+
35+
# Login against a Docker registry except on PR
36+
# https://github.com/docker/login-action
37+
- name: Log into registry ${{ env.REGISTRY }}
38+
if: github.event_name != 'pull_request'
39+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
40+
with:
41+
registry: ${{ env.REGISTRY }}
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.CR_PAT }}
44+
45+
# Extract metadata (tags, labels) for Docker
46+
# https://github.com/docker/metadata-action
47+
- name: Extract Docker metadata
48+
id: meta
49+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
50+
with:
51+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
52+
53+
# Build and push Docker image with Buildx (don't push on PR)
54+
# https://github.com/docker/build-push-action
55+
- name: Build and push Docker image
56+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
57+
with:
58+
context: .
59+
push: ${{ github.event_name != 'pull_request' }}
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}

Cargo.lock

Lines changed: 67 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
[dependencies]
88
actix-multipart = "0.4.0"
99
actix-web = "4.0.1"
10-
actix-web-codegen = { path = "../actix-web/actix-web-codegen/" }
10+
actix-web-codegen = { git = "https://github.com/ModProg/actix-web", branch = "advanced_route_macro" }
1111
actix-web-lab = "0.15.0"
1212
anyhow = "1.0.56"
1313
async-trait = "0.1.53"

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM rust as build
2+
3+
WORKDIR /usr/src
4+
RUN USER=root cargo new pastemp
5+
WORKDIR /usr/src/pastemp
6+
7+
# Caches build dependencies by writing placeholder lib and main files.
8+
COPY Cargo.toml Cargo.lock ./
9+
10+
COPY src ./src
11+
COPY config.toml ./
12+
13+
RUN cargo install --path .
14+
15+
FROM debian:buster-slim
16+
17+
RUN apt-get update
18+
19+
COPY --from=build /usr/local/cargo/bin/pastemp /usr/local/bin/pastemp
20+
21+
EXPOSE 8000
22+
CMD ["pastemp"]
23+

src/simple.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async fn get_bin(
5454
database: Data<AsyncDatabase>,
5555
Query(MimeQuery { mime }): Query<MimeQuery>,
5656
) -> Result<impl Responder> {
57-
if let Some(file) = BonsaiFiles::load_async(&id, database.as_ref().clone())
57+
if let Some(file) = BonsaiFiles::load_async(&id, database.as_ref())
5858
.await
5959
.map_err(ErrorInternalServerError)?
6060
{
@@ -79,7 +79,7 @@ async fn get_ext(
7979
database: Data<AsyncDatabase>,
8080
syntaxes: Data<SyntaxSet>,
8181
) -> Result<impl Responder> {
82-
if let Some(file) = BonsaiFiles::load_async(&id, database.as_ref().clone())
82+
if let Some(file) = BonsaiFiles::load_async(&id, database.as_ref())
8383
.await
8484
.map_err(ErrorInternalServerError)?
8585
{
@@ -190,7 +190,7 @@ async fn delete_entry(
190190
Path(Id { id, .. }): Path<Id>,
191191
database: Data<AsyncDatabase>,
192192
) -> Result<impl Responder> {
193-
if let Some(file) = BonsaiFiles::load_async(&id, database.as_ref().clone())
193+
if let Some(file) = BonsaiFiles::load_async(&id, database.as_ref())
194194
.await
195195
.map_err(ErrorInternalServerError)?
196196
{
@@ -229,15 +229,12 @@ async fn post_form(payload: Multipart, database: Data<AsyncDatabase>) -> Result<
229229
let file = loop {
230230
let name = ReadableAlphanumeric.sample_string(&mut rand::thread_rng(), length);
231231
tries += 1;
232-
match BonsaiFiles::build(&name)
233-
.create_async(database.clone())
234-
.await
235-
{
232+
match BonsaiFiles::build(&name).create_async(database).await {
236233
Ok(file) => break file,
237234
Err(bonsaidb_files::Error::Database(bonsaidb::core::Error::UniqueKeyViolation {
238235
..
239236
})) if tries > 5 => {
240-
let file = BonsaiFiles::load_or_create_async(&name, true, database.clone())
237+
let file = BonsaiFiles::load_or_create_async(&name, true, database)
241238
.await
242239
.map_err(ErrorInternalServerError)?;
243240
file.truncate(0, Truncate::RemovingStart)

0 commit comments

Comments
 (0)