-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
225 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- develop | ||
- devops-1286 | ||
tags-ignore: | ||
- "**" | ||
paths-ignore: | ||
- "**/CHANGELOG.md" | ||
- "**/package.json" | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} | ||
fetch-depth: 0 | ||
persist-credentials: false | ||
|
||
- name: Semantic Release | ||
uses: cycjimmy/semantic-release-action@v3 | ||
id: semantic | ||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | ||
SEMANTIC_RELEASE_PACKAGE: ${{ github.event.repository.name }} | ||
with: | ||
branch: main | ||
semantic_version: 19 | ||
extra_plugins: | | ||
@semantic-release/changelog | ||
@semantic-release/git | ||
@semantic-release/exec | ||
conventional-changelog-conventionalcommits | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Docker Meta | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: | | ||
hirosystems/${{ github.event.repository.name }} | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}},value=${{ steps.semantic.outputs.new_release_version }},enable=${{ steps.semantic.outputs.new_release_version != '' }} | ||
type=semver,pattern={{major}}.{{minor}},value=${{ steps.semantic.outputs.new_release_version }},enable=${{ steps.semantic.outputs.new_release_version != '' }} | ||
type=raw,value=latest,enable={{is_default_branch}} | ||
- name: Create artifact directory | ||
run: mkdir -p /tmp/artifacts | ||
|
||
- name: Build/Save Image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
tags: ${{ steps.meta.outputs.tags }}, | ||
labels: ${{ steps.meta.outputs.labels }} | ||
outputs: type=docker,dest=/tmp/artifacts/myimage.tar | ||
|
||
- name: Save docker artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: docker-image | ||
path: /tmp/artifacts/myimage.tar | ||
|
||
- name: Create Version Artifact | ||
run: | | ||
echo "${{ steps.meta.outputs.Version }}" > version.txt | ||
id: create_artifact | ||
|
||
- name: Upload Version Artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: version-artifact | ||
path: version.txt | ||
|
||
k8s-tests: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
|
||
steps: | ||
- name: Download Version Artifact | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: version-artifact | ||
path: artifacts | ||
|
||
- name: Read version into env var | ||
run: | | ||
echo "version_tag=$(cat artifacts/version.txt)" >> $GITHUB_ENV | ||
echo "Extracted version tag: $version_tag" | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Build k8s cluster | ||
uses: nolar/setup-k3d-k3s@v1 | ||
with: | ||
version: v1.26 | ||
k3d-name: k3d-kube | ||
k3d-args: "--no-lb --no-rollback --k3s-arg --disable=traefik,servicelb,metrics-server@server:*" | ||
|
||
- name: Pull docker image artifact from previous docker job | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: docker-image | ||
path: /tmp/artifacts | ||
|
||
- name: Load image | ||
run: | | ||
docker load --input /tmp/artifacts/myimage.tar | ||
docker tag hirosystems/stacks-devnet-api:$version_tag hirosystems/stacks-devnet-api:latest | ||
docker image ls -a | ||
- run: k3d image import hirosystems/stacks-devnet-api:latest -c k3d-kube | ||
- run: kubectl create namespace devnet | ||
- run: kubectl create configmap stacks-devnet-api-conf --from-file=./Config.toml --namespace devnet | ||
- run: kubectl apply -f ./templates/stacks-devnet-api.template.yaml | ||
|
||
- name: Sleep for 30 seconds | ||
run: sleep 30s | ||
shell: bash | ||
|
||
- run: kubectl get all --all-namespaces | ||
- run: kubectl -n devnet get cm | ||
- run: kubectl -n devnet describe po stacks-devnet-api | ||
- run: kubectl -n devnet logs stacks-devnet-api | ||
|
||
- name: Install stable toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
override: true | ||
|
||
- name: Run cargo-tarpaulin | ||
uses: actions-rs/[email protected] | ||
with: | ||
version: '0.15.0' | ||
args: '-- --test-threads 2' | ||
|
||
build-publish-release: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- build | ||
- k8s-tests | ||
if: needs.build.result == 'success' && needs.k8s-tests.result == 'success' | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} | ||
fetch-depth: 0 | ||
persist-credentials: false | ||
|
||
- name: Semantic Release | ||
uses: cycjimmy/semantic-release-action@v3 | ||
id: semantic | ||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | ||
SEMANTIC_RELEASE_PACKAGE: ${{ github.event.repository.name }} | ||
with: | ||
branch: main | ||
semantic_version: 19 | ||
extra_plugins: | | ||
@semantic-release/changelog | ||
@semantic-release/git | ||
@semantic-release/exec | ||
conventional-changelog-conventionalcommits | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Docker Meta | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: | | ||
hirosystems/${{ github.event.repository.name }} | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}},value=${{ steps.semantic.outputs.new_release_version }},enable=${{ steps.semantic.outputs.new_release_version != '' }} | ||
type=semver,pattern={{major}}.{{minor}},value=${{ steps.semantic.outputs.new_release_version }},enable=${{ steps.semantic.outputs.new_release_version != '' }} | ||
type=raw,value=latest,enable={{is_default_branch}} | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
||
- name: Build/Push Image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
tags: ${{ steps.meta.outputs.tags }}, | ||
labels: ${{ steps.meta.outputs.labels }} | ||
# Only push if (there's a new release on main branch, or if building a non-main branch) and (Only run on non-PR events or only PRs that aren't from forks) | ||
push: ${{ (github.ref != 'refs/heads/main' || steps.semantic.outputs.new_release_version != '') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
FROM arm64v8/rust:1.67 as builder | ||
|
||
WORKDIR ./ | ||
COPY . ./ | ||
FROM rust:bullseye as builder | ||
WORKDIR /src | ||
RUN apt update && apt install -y ca-certificates pkg-config libssl-dev libclang-11-dev | ||
RUN rustup update 1.67.0 && rustup default 1.67.0 | ||
COPY . /src | ||
|
||
RUN mkdir /out | ||
RUN cargo build --release --manifest-path ./Cargo.toml | ||
RUN cp target/release/stacks-devnet-api /out | ||
|
||
FROM gcr.io/distroless/cc | ||
COPY --from=builder target/release/stacks-devnet-api / | ||
FROM debian:bullseye-slim | ||
COPY --from=builder /out/ /bin/ | ||
|
||
ENTRYPOINT ["./stacks-devnet-api"] | ||
CMD ["stacks-devnet-api"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters