feat: alpine dockerfile (#470)

* feat: alpine dockerfile

* Create docker-publish.yml

---------

Co-authored-by: Daniel <102395937+maddsua@users.noreply.github.com>
This commit is contained in:
Alexander Ng 2023-12-05 13:52:45 -08:00 committed by GitHub
parent 3b7ae6a886
commit 9de89415f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 0 deletions

17
.dockerignore Normal file
View file

@ -0,0 +1,17 @@
Dockerfile
bin/
npm-install/
target/
.cargo/
.git/
.github/
CONTRIBUTING.md
LICENSE
README.md
flake.*
package.json
install.sh
pnpm-lock.yaml
release.toml
shell.nix
v2.sh

72
.github/workflows/docker-publish.yml vendored Normal file
View file

@ -0,0 +1,72 @@
name: Docker
on:
release:
types: [published]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Install the cosign tool
# https://github.com/sigstore/cosign-installer
- name: Install cosign
uses: sigstore/cosign-installer@v3.1.0
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2.10.0
# Login against a Docker registry
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2.2.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4.6.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4.1.1
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Sign the resulting Docker image digest
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
env:
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

13
Dockerfile Normal file
View file

@ -0,0 +1,13 @@
FROM rust:1-alpine3.18 as builder
WORKDIR /app
COPY . .
RUN apk add --no-cache musl-dev openssl-dev
RUN cargo build --release
FROM alpine:3.18
COPY --from=builder /app/target/release/railway /usr/bin/railway