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

Add GitHub actions #4

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 31 additions & 0 deletions .github/steps/publish-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -euo pipefail

docker images
while getopts u:p:b:t: option
do
case "${option}" in
u) user=${OPTARG};;
p) password=${OPTARG};;
b) branch=${OPTARG};;
t) tag=${OPTARG};;
*) echo -e "usage: $0 \n [-u] docker hub user \n [-p] docker hub password \n [-b] current branch \n [-t] governance-cli tag" >&2
exit 1 ;;
esac
done

if [[ $branch == "main" ]]; then
TAG="stable"
else
TAG=$branch
fi

docker login -u=$user -p=$password
docker push neonlabsorg/neon-governance:$tag

if [[ $TAG == "stable" ]] || [[ $TAG == ci-* ]] || [[ $TAG == v*.*.* ]]; then
docker tag neonlabsorg/neon-governance:$tag neonlabsorg/neon-governance:${TAG}
docker push neonlabsorg/neon-governance:${TAG}
fi

exit 0
68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: ci

on: [push]

env:
SOLANA_REVISION: v1.10.29
GITHUB_SHA: ${{ github.sha }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
DOCKER_HUB_PASSWORD: ${{ secrets.DHUBP }}
DOCKER_HUB_USER: ${{ secrets.DHUBU }}

jobs:
neon-governance-deploy:
runs-on: build-runner
env:
NEON_GOVERNANCE_IMAGE: neonlabsorg/neon-governance:${GITHUB_SHA}
steps:
- uses: actions/checkout@v2
- name: "Checkout submodules using a Personal Access Token"
run: |
git config --file .gitmodules --get-regexp url | while read url; do
git config --file=.gitmodules $(echo "$url" | sed -E "s/[email protected]:|https:\/\/github.com\//https:\/\/${{ secrets.CI_PAT }}:${{ secrets.CI_PAT }}@github.com\//")
done
git submodule sync
git submodule update --init --recursive

- name: "Prepare to build image"
id: prep
run: |
docker pull solanalabs/solana:${SOLANA_REVISION}
IMAGE="neonlabsorg/neon-governance"
echo ::set-output name=tagged_image::${IMAGE}:${GITHUB_SHA}

- name: "Set up Docker Buildx"
id: buildx
uses: docker/setup-buildx-action@v2
with:
version: v0.9.1
install: true

- name: "Cache Docker layers"
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-multi-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-multi-buildx

- name: "Build image"
uses: docker/build-push-action@v3
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
file: Dockerfile
target: base
push: false
load: true
tags: ${{ steps.prep.outputs.tagged_image }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new

- name: "Move cache"
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

- name: "Publish the Docker image"
run: ./.github/steps/publish-image.sh -u ${DOCKER_HUB_USER} -p ${DOCKER_HUB_PASSWORD} -b ${BRANCH_NAME} -t ${GITHUB_SHA}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Install BPF SDK
FROM solanalabs/rust:1.62.0 AS builder
# Use hardcoded solana revision for install SDK to prevent long rebuild when use other SOLANA_REVISION
RUN sh -c "$(curl -sSfL https://release.solana.com/v1.10.29/install)" && \
RUN sh -c "$(curl -sSfL https://release.solana.com/v1.14.24/install)" && \
/root/.local/share/solana/install/active_release/bin/sdk/bpf/scripts/install.sh
ENV PATH=/root/.local/share/solana/install/active_release/bin:/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Expand Down
Loading