Skip to content

Commit

Permalink
Add GitHub actions (#4)
Browse files Browse the repository at this point in the history
* Add build by GitHub actions

---------

Co-authored-by: Semen Medvedev <[email protected]>
  • Loading branch information
s-medvedev and Semen Medvedev authored Aug 22, 2024
1 parent eb9cfe8 commit aaae54e
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
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

0 comments on commit aaae54e

Please sign in to comment.