Skip to content

Commit

Permalink
feat: Add docker support for proxy (#133)
Browse files Browse the repository at this point in the history
* add docker

* add GOPRIVATE

* add GOPRIVATE

* add go

* add build in action

* add build in action

* add git configs

* fix run
  • Loading branch information
fyInALT authored May 12, 2024
1 parent 31e888a commit 0e29e8a
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release-aggregator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
SUBWASM_VERSION: v0.20.0
CARGO_INCREMENTAL: "0"
CARGO_NET_GIT_FETCH_WITH_CLI: true
GOPRIVATE: github.com/alt-research/avs-generic-aggregator
ECR_REPO: 305587085711.dkr.ecr.us-west-2.amazonaws.com/mach-aggregator
PUB_REPO: public.ecr.aws

Expand Down
117 changes: 117 additions & 0 deletions .github/workflows/release-operator-proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Release Operator Proxy
on:
push:
tags: ["*"]
workflow_dispatch:
# pull_request: # for testing only
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
# https://github.com/mozilla/sccache/releases
SCCACHE_TAR_URL: https://github.com/mozilla/sccache/releases/download/v0.7.4/sccache-v0.7.4-x86_64-unknown-linux-musl.tar.gz
SCCACHE_CACHE_SIZE: "3G"
RUSTC_WRAPPER: sccache
SUBWASM_VERSION: v0.20.0
CARGO_INCREMENTAL: "0"
CARGO_NET_GIT_FETCH_WITH_CLI: true
GOPRIVATE: github.com/alt-research/avs-generic-aggregator
ECR_REPO: 305587085711.dkr.ecr.us-west-2.amazonaws.com/mach-operator-proxy
PUB_REPO: public.ecr.aws

jobs:
build-docker-image:
name: Build Docker Image and extract files
runs-on: ["self-hosted", "linux", "x64", "ubuntu-latest"]
steps:
- name: Login to ECR
uses: docker/login-action@v3
with:
registry: ${{ env.ECR_REPO }}
username: ${{ secrets.ECR_ACCESS_KEY_ID }}
password: ${{ secrets.ECR_ACCESS_KEY }}

- name: Login to public ECR
uses: docker/login-action@v3
with:
registry: ${{ env.PUB_REPO }}
username: ${{ secrets.ECR_ACCESS_KEY_ID }}
password: ${{ secrets.ECR_ACCESS_KEY }}

- name: Checkout Sources
uses: actions/checkout@v4
with:
submodules: "true"
token: ${{ secrets.GIT_CREDENTIALS }}

- uses: de-vri-es/setup-git-credentials@v2
with:
credentials: https://${{ secrets.GIT_USERNAME }}:${{ secrets.GIT_CREDENTIALS }}@github.com

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
id: docker-builder
uses: docker/setup-buildx-action@v3

- name: Prepare Environment Variables
run: |
echo "HOME=$HOME" | tee -a $GITHUB_ENV
echo "XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}" | tee -a $GITHUB_ENV
echo "SHORT_SHA=${GITHUB_SHA::7}" | tee -a $GITHUB_ENV
GIT_TAG=$(git tag --points-at HEAD)
echo "GIT_TAG=$GIT_TAG" | tee -a $GITHUB_ENV
GIT_BRANCH=$(git branch --show-current)
echo "GIT_BRANCH=$GIT_BRANCH" | tee -a $GITHUB_ENV
echo "REF_NAME=$(echo ${GIT_TAG:-$GITHUB_REF_NAME} | sed 's/[^a-zA-Z0-9._]/-/g')" | tee -a $GITHUB_ENV
- run: cat $HOME/.gitconfig && cat $XDG_CONFIG_HOME/git/credentials

- name: Set up Golang
uses: actions/setup-go@v5
with:
go-version: '1.21.1' # The Go version to download (if necessary) and use.
- run: go version
- run: go mod download && go mod tidy && go mod verify
- run: go build -o ./bin/mach-operator-proxy ./generic-operator-proxy/cmd

- name: Extract operator metadata (tags, labels) for Docker
id: operator-meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.ECR_REPO }}
${{ env.PUB_REPO }}/altlayer/mach-operator-proxy
flavor: |
prefix=
suffix=
tags: |
type=sha,format=short,prefix=
type=ref,event=branch
type=ref,event=branch,suffix=-${{ github.run_number }}
type=ref,event=tag
type=raw,value=${{ env.REF_NAME }},enable=${{ github.event_name == 'pull_request' }}
type=raw,value=${{ env.GIT_BRANCH }},enable=${{ env.GIT_BRANCH != '' }}
type=raw,value=latest,enable=${{ env.GIT_BRANCH == 'master' }}
- name: Build operator docker with cache and push images
uses: docker/build-push-action@v5
id: docker_operator_build
with:
context: .
builder: ${{ steps.docker-builder.outputs.name }}
target: app
push: ${{ github.event_name != 'pull_request' }}
provenance: false
cache-from: |
type=registry,ref=${{ env.ECR_REPO }}:latest
type=registry,ref=${{ env.ECR_REPO }}:${{ env.REF_NAME }}
secret-files: |
git_config=${{ env.HOME }}/.gitconfig
git_credentials=${{ env.XDG_CONFIG_HOME }}/git/credentials
file: ./ops/proxy.Dockerfile
labels: ${{ steps.operator-meta.outputs.labels }}
tags: ${{ steps.operator-meta.outputs.tags }}


1 change: 1 addition & 0 deletions .github/workflows/release-operator-tool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
SUBWASM_VERSION: v0.20.0
CARGO_INCREMENTAL: "0"
CARGO_NET_GIT_FETCH_WITH_CLI: true
GOPRIVATE: github.com/alt-research/avs-generic-aggregator
ECR_REPO: 305587085711.dkr.ecr.us-west-2.amazonaws.com/mach-operator-tool
PUB_REPO: public.ecr.aws

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
SUBWASM_VERSION: v0.20.0
CARGO_INCREMENTAL: "0"
CARGO_NET_GIT_FETCH_WITH_CLI: true
GOPRIVATE: github.com/alt-research/avs-generic-aggregator
ECR_REPO: 305587085711.dkr.ecr.us-west-2.amazonaws.com/mach-operator
PUB_REPO: public.ecr.aws

Expand Down
21 changes: 19 additions & 2 deletions ops/aggregator.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@ WORKDIR /usr/src/app

COPY go.mod go.sum ./

RUN go mod download && go mod tidy && go mod verify
ENV GOPRIVATE=github.com/alt-research/avs-generic-aggregator
ARG XDG_CONFIG_HOME=/root/.config/

RUN \
--mount=type=secret,id=gh_hosts,target=/root/.config/gh/hosts.yml \
--mount=type=secret,id=git_config,target=/root/.gitconfig \
--mount=type=secret,id=git_credentials,target=/root/.git-credentials \
<<EOF
set -ex
go mod download && go mod tidy && go mod verify
EOF

COPY . .

WORKDIR /usr/src/app/aggregator/cmd
RUN go build -v -o /usr/local/bin/aggregator ./...
RUN \
--mount=type=secret,id=gh_hosts,target=/root/.config/gh/hosts.yml \
--mount=type=secret,id=git_config,target=/root/.gitconfig \
--mount=type=secret,id=git_credentials,target=/root/.git-credentials \
<<EOF
set -ex
go build -v -o /usr/local/bin/aggregator ./...
EOF

FROM debian:bullseye as app
COPY --from=build /usr/local/bin/aggregator /usr/local/bin/aggregator
Expand Down
21 changes: 19 additions & 2 deletions ops/operator-tool.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,28 @@ WORKDIR /usr/src/app

COPY go.mod go.sum ./

RUN go mod download && go mod tidy && go mod verify
ENV GOPRIVATE=github.com/alt-research/avs-generic-aggregator
ARG XDG_CONFIG_HOME=/root/.config/

RUN \
--mount=type=secret,id=gh_hosts,target=/root/.config/gh/hosts.yml \
--mount=type=secret,id=git_config,target=/root/.gitconfig \
--mount=type=secret,id=git_credentials,target=/root/.git-credentials \
<<EOF
set -ex
go mod download && go mod tidy && go mod verify
EOF

COPY . .

RUN make build-cli
RUN \
--mount=type=secret,id=gh_hosts,target=/root/.config/gh/hosts.yml \
--mount=type=secret,id=git_config,target=/root/.gitconfig \
--mount=type=secret,id=git_credentials,target=/root/.git-credentials \
<<EOF
set -ex
make build-cli
EOF

RUN cp ./bin/mach-operator-cli /usr/local/bin/mach-operator-cli

Expand Down
21 changes: 19 additions & 2 deletions ops/operator.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@ WORKDIR /usr/src/app

COPY go.mod go.sum ./

RUN go mod download && go mod tidy && go mod verify
ENV GOPRIVATE=github.com/alt-research/avs-generic-aggregator
ARG XDG_CONFIG_HOME=/root/.config/

RUN \
--mount=type=secret,id=gh_hosts,target=/root/.config/gh/hosts.yml \
--mount=type=secret,id=git_config,target=/root/.gitconfig \
--mount=type=secret,id=git_credentials,target=/root/.git-credentials \
<<EOF
set -ex
go mod download && go mod tidy && go mod verify
EOF

COPY . .

WORKDIR /usr/src/app/operator/cmd
RUN go build -v -o /usr/local/bin/operator ./...
RUN \
--mount=type=secret,id=gh_hosts,target=/root/.config/gh/hosts.yml \
--mount=type=secret,id=git_config,target=/root/.gitconfig \
--mount=type=secret,id=git_credentials,target=/root/.git-credentials \
<<EOF
set -ex
go build -v -o /usr/local/bin/operator ./...
EOF

FROM debian:bullseye as app
COPY --from=build /usr/local/bin/operator /usr/local/bin/operator
Expand Down
40 changes: 40 additions & 0 deletions ops/proxy.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM golang:1.21-bullseye as build

WORKDIR /usr/src/app

COPY go.mod go.sum ./

ENV GOPRIVATE=github.com/alt-research/avs-generic-aggregator
ARG XDG_CONFIG_HOME=/root/.config/

RUN \
--mount=type=secret,id=gh_hosts,target=/root/.config/gh/hosts.yml \
--mount=type=secret,id=git_config,target=/root/.gitconfig \
--mount=type=secret,id=git_credentials,target=/root/.git-credentials \
<<EOF
set -ex
go mod download && go mod tidy && go mod verify
EOF

COPY . .

WORKDIR /usr/src/app/generic-operator-proxy/cmd

RUN \
--mount=type=secret,id=gh_hosts,target=/root/.config/gh/hosts.yml \
--mount=type=secret,id=git_config,target=/root/.gitconfig \
--mount=type=secret,id=git_credentials,target=/root/.git-credentials \
<<EOF
set -ex
go build -v -o /usr/local/bin/generic-operator-proxy ./...
EOF

FROM debian:bullseye as app
COPY --from=build /usr/local/bin/generic-operator-proxy /usr/local/bin/mach-operator-proxy

RUN apt-get update && \
apt-get install --no-install-recommends -y curl sudo daemontools jq ca-certificates && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

ENTRYPOINT [ "mach-operator-proxy"]

0 comments on commit 0e29e8a

Please sign in to comment.