Skip to content

Commit a1f7734

Browse files
authored
Merge pull request #22 from ChillFish8/create-dockerfile-and-wf
Create dockerfile and Workflow
2 parents 9fd94ce + 722f598 commit a1f7734

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

.github/workflows/docker-publish.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
schedule:
10+
- cron: '35 8 * * *'
11+
push:
12+
branches: [ master ]
13+
# Publish semver tags as releases.
14+
tags: [ '*.*.*' ]
15+
pull_request:
16+
branches: [ master ]
17+
18+
env:
19+
# Use docker.io for Docker Hub if empty
20+
REGISTRY: docker.io
21+
# github.repository as <account>/<repo>
22+
IMAGE_NAME: chillfish8/rewrk
23+
24+
25+
jobs:
26+
build:
27+
28+
runs-on: ubuntu-latest
29+
permissions:
30+
contents: read
31+
packages: write
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v2
36+
37+
# Login against a Docker registry except on PR
38+
# https://github.com/docker/login-action
39+
- name: Log into registry ${{ env.REGISTRY }}
40+
if: github.event_name != 'pull_request'
41+
uses: docker/[email protected]
42+
with:
43+
username: ${{secrets.DOCKER_USERNAME}}
44+
password: ${{secrets.DOCKER_PASSWORD}}
45+
46+
# Extract metadata (tags, labels) for Docker
47+
# https://github.com/docker/metadata-action
48+
- name: Extract Docker metadata
49+
id: meta
50+
uses: docker/metadata-action@v2
51+
with:
52+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
53+
54+
# Build and push Docker image with Buildx (don't push on PR)
55+
# https://github.com/docker/build-push-action
56+
- name: Build and push Docker image
57+
uses: docker/build-push-action@v2
58+
with:
59+
context: .
60+
push: ${{ github.event_name != 'pull_request' }}
61+
tags: ${{ steps.meta.outputs.tags }}
62+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM chillfish8/rust-builder:latest as builder
2+
3+
WORKDIR /home/rust/
4+
5+
# Avoid having to install/build all dependencies by copying
6+
# the Cargo files and making a dummy src/main.rs
7+
COPY . .
8+
RUN cargo build --release --target x86_64-unknown-linux-musl
9+
10+
# Size optimization
11+
RUN strip target/x86_64-unknown-linux-musl/release/rewrk
12+
13+
# Start building the final image
14+
FROM scratch
15+
WORKDIR /etc/rewrk
16+
17+
COPY --from=builder /home/rust/target/x86_64-unknown-linux-musl/release/rewrk .
18+
ENTRYPOINT ["./rewrk"]

0 commit comments

Comments
 (0)