Skip to content

Commit

Permalink
Initial container implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 committed Nov 8, 2023
1 parent 8ea862d commit 2b9da9a
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/ci-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build Image CI

on:
workflow_dispatch:
pull_request:
branches:
- main
push:
branches:
- "*"

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64
push: false
build-args: |
VERSION=latest
64 changes: 64 additions & 0 deletions .github/workflows/ghcr-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Deploy Image CI

on:
push:
tags:
- "*"

concurrency:
group: "docker-image"
cancel-in-progress: true

env:
DOCKER_BUILDKIT: "1"

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Generate repository name
run: |
echo "REPOSITORY_PATH=$( echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]' )" >> ${GITHUB_ENV}
echo "REPOSITORY_SHA=$( echo ${GITHUB_SHA} | cut -c 1-7 )" >> ${GITHUB_ENV}
-
name: Build and Push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
build-args: |
VERSION=${{ github.ref_name }}
tags: |
ghcr.io/${{ env.REPOSITORY_PATH }}:v${{ github.ref_name }}
ghcr.io/${{ env.REPOSITORY_PATH }}:${{ env.REPOSITORY_SHA }}
ghcr.io/${{ env.REPOSITORY_PATH }}:latest
-
name: GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: false
prerelease: false
tag_name: ${{ github.ref_name }}
release_name: v${{ github.ref_name }}
body_path: CHANGELOG.md
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1.0.0 (2023-11-08)

* initial rust container
84 changes: 84 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
FROM debian:stable-slim as builder
# defined from build kit
# DOCKER_BUILDKIT=1 docker build . -t ...
ARG TARGETARCH

RUN export DEBIAN_FRONTEND=noninteractive && \
apt update && \
apt install -y -q --no-install-recommends \
git curl gnupg2 build-essential \
linux-headers-${TARGETARCH} libc6-dev \
openssl libssl-dev pkg-config \
ca-certificates apt-transport-https \
python3 && \
apt clean && \
rm -rf /var/lib/apt/lists/*

RUN useradd --create-home -s /bin/bash xmtp
RUN usermod -a -G sudo xmtp
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

WORKDIR /rustup
## Rust
ADD https://sh.rustup.rs /rustup/rustup.sh
RUN chmod 755 /rustup/rustup.sh

ENV USER=xmtp
USER xmtp
RUN /rustup/rustup.sh -y --default-toolchain stable --profile minimal

ENV PATH=$PATH:~xmtp/.cargo/bin

FROM debian:stable-slim
ARG TARGETARCH

RUN export DEBIAN_FRONTEND=noninteractive && \
apt update && \
apt install -y -q --no-install-recommends \
ca-certificates apt-transport-https \
sudo ripgrep procps build-essential \
python3 python3-pip python3-dev \
git curl protobuf-compiler && \
apt clean && \
rm -rf /var/lib/apt/lists/*

RUN echo "building platform $(uname -m)"

RUN useradd --create-home -s /bin/bash xmtp
RUN usermod -a -G sudo xmtp
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

## Node and NPM
RUN mkdir -p /usr/local/nvm
ENV NVM_DIR=/usr/local/nvm

ENV NODE_VERSION=v20.9.0

ADD https://raw.githubusercontent.com/creationix/nvm/master/install.sh /usr/local/etc/nvm/install.sh
RUN bash /usr/local/etc/nvm/install.sh && \
bash -c ". $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm alias default $NODE_VERSION && nvm use default"

ENV NVM_NODE_PATH ${NVM_DIR}/versions/node/${NODE_VERSION}
ENV NODE_PATH ${NVM_NODE_PATH}/lib/node_modules
ENV PATH ${NVM_NODE_PATH}/bin:$PATH

RUN npm install npm -g
RUN npm install yarn -g


## Rust from builder
COPY --chown=xmtp:xmtp --from=builder /home/xmtp/.cargo /home/xmtp/.cargo
COPY --chown=xmtp:xmtp --from=builder /home/xmtp/.rustup /home/xmtp/.rustup

USER xmtp

LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="rust" \
org.label-schema.description="Rust Development Container" \
org.label-schema.url="https://github.com/xmtp/rust" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="git@github.com:xmtp/rust.git" \
org.label-schema.vendor="xmtp" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0" \
org.opencontainers.image.description="Rust Development Container"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 XMTP

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 15 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

# install a local version of this image - useful on arm64 where there are currently no public
# distributions

VERSION=$(git rev-parse HEAD | cut -c 1-8)

PROJECT=xmtp/$(basename ${PWD})

# cross platform okay:
# --platform=amd64 or arm64
DOCKER_BUILDKIT=1 docker build --progress plain . -t ${PROJECT}:${VERSION} \
--build-arg VERSION=${VERSION} --build-arg MAXIMUM_THREADS=2 && \
docker tag ${PROJECT}:${VERSION} ${PROJECT}:latest && \
docker tag ${PROJECT}:${VERSION} ghcr.io/${PROJECT}:latest

0 comments on commit 2b9da9a

Please sign in to comment.