Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds Dockerfile and GHA Workflow #3

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Release
on:
push:
branches-ignore:
- '**'
tags:
- 'v*.*.*'
- 'v*.*.*-*'
jobs:
binary_linux_amd64:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Install Cargo Deps And Build Bridge API
shell: bash
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
source "$HOME/.cargo/env"
sudo apt-get update && sudo apt-get install -y protobuf-compiler pkg-config
cargo build --profile maxperf -p bridge-api
mv target/maxperf/bridge-api target/maxperf/bridge-api-linux-amd64
pushd target/maxperf/
tar czf bridge-api-linux-amd64.tar.gz bridge-api-linux-amd64
popd
- uses: actions/upload-artifact@v4
with:
name: bridge-api-linux-amd64-binary
path: target/maxperf/bridge-api-linux-amd64.tar.gz

binary_publish:
needs: [binary_linux_amd64]
runs-on: ubuntu-20.04
steps:
- uses: actions/download-artifact@v4
with:
name: bridge-api-linux-amd64-binary
- name: Export Tag Var
id: prepare
run: |
TAG=${GITHUB_REF#refs/tags/}
echo ::set-output name=tag_name::${TAG}
- name: Publish Binaries
uses: svenstaro/upload-release-action@v3
with:
repo_token: ${{ secrets.PAT_TOKEN }}
file: /home/runner/work/bridge-api/bridge-api/bridge-api*
release_name: ${{ steps.prepare.outputs.tag_name }}
tag: ${{ steps.prepare.outputs.tag_name }}
overwrite: true
file_glob: true

docker_build_push:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Export Tag Var
id: prepare
run: |
TAG=${GITHUB_REF#refs/tags/}
echo ::set-output name=tag_name::${TAG}
- name: Sets Digital Ocean Registry
id: sets_do_registry
run: |
echo ::set-output name=do_registry::registry.digitalocean.com
- name: Login to Digital Ocean Registry
uses: docker/login-action@v3
with:
registry: ${{ steps.sets_do_registry.outputs.do_registry }}
username: ${{ secrets.DO_USER_EMAIL }}
password: ${{ secrets.DO_USER_TOKEN }}
- name: Build and push images
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.sets_do_registry.outputs.do_registry }}/availj/bridge-api:${{ steps.prepare.outputs.tag_name }}
build-args: |
BUILD_PROFILE=release
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM rust:1.76.0-slim AS builder
WORKDIR /build
COPY . .
ARG BUILD_PROFILE=release

RUN apt update && apt install -y make libssl-dev pkg-config \
&& cargo build --profile $BUILD_PROFILE --locked \
&& cp /build/target/$BUILD_PROFILE/bridge-api /build/bridge-api

FROM ubuntu:22.04 as run
WORKDIR /app

COPY --from=builder /build/bridge-api /usr/local/bin

RUN adduser --disabled-password --gecos "" --no-create-home --uid 1000 bridge \
&& apt-get update && apt-get install -y ca-certificates \
&& apt clean \
&& chown -R bridge:bridge /usr/local/bin/bridge-api

USER bridge

EXPOSE 8080

ENTRYPOINT ["/usr/local/bin/bridge-api"]
Loading