Skip to content

Commit

Permalink
Improve the setup of the Indexer, including build pipelines and deplo…
Browse files Browse the repository at this point in the history
…y of Docker image (#3)

* Feature/deployment preparations (#1)

* Add a prepare docker-compose for Indexer

- The docker-compose must be moved out of this repo when the time comes.
- Refactoring and updates to the Indexer.

* Add grace shutdown periode for the containers

- Add artifact publish on the build.
- Make docker only build on release, it will eventually be changed to build from binaries and not source.

* Add CI/CD flows for deployment

* Testing event and updating docker to use binaries

* Update README with release process

- Improved file names for Docker.
- Removed the test and publish workflows.

* Update code to align to the blockcore repo
  • Loading branch information
sondreb authored Feb 2, 2020
1 parent 0e70e69 commit adaf19f
Show file tree
Hide file tree
Showing 38 changed files with 232 additions and 348 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
18 changes: 13 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Build and Release Binaries

on:
push:
Expand All @@ -7,7 +7,7 @@ on:

jobs:

buildTestRelease:
build:

strategy:
matrix:
Expand Down Expand Up @@ -57,10 +57,10 @@ jobs:
run: dotnet restore ${{env.SOLUTION_PATH}}

- name: Build
run: dotnet build -c ${{env.BUILD_CONFIGURATION}} -r ${{env.RELEASE_CONFIGURATION}} -v m ${{env.SOLUTION_PATH}}
run: dotnet build -c ${{env.BUILD_CONFIGURATION}} -r ${{env.RELEASE_CONFIGURATION}} /p:Version=${{ env.VERSION }} -v m ${{env.SOLUTION_PATH}}

- name: Publish
run: dotnet publish -c ${{env.BUILD_CONFIGURATION}} -r ${{env.RELEASE_CONFIGURATION}} -v m -o ./src/${{ env.PROJECT_NAME }}/bin/publish ${{env.PROJECT_PATH}}
run: dotnet publish -c ${{env.BUILD_CONFIGURATION}} -r ${{env.RELEASE_CONFIGURATION}} /p:Version=${{ env.VERSION }} -v m -o ./src/${{ env.PROJECT_NAME }}/bin/publish ${{env.PROJECT_PATH}}

- name: Package Name
run: |
Expand All @@ -80,6 +80,14 @@ jobs:
if: matrix.os == 'macos-latest'
run: zip -j -r ${{env.RELEASE_NAME}} ./src/${{env.PROJECT_NAME}}/bin/publish/

#- run: mkdir -p path/to/artifact
#- run: echo hello > path/to/artifact/world.txt

- uses: actions/upload-artifact@v1
with:
name: blockcore-indexer
path: "${{env.RELEASE_PATH}}"

- name: Release
uses: sondreb/action-release@master
with:
Expand All @@ -89,4 +97,4 @@ jobs:
prerelease: true
body: ''
name: "Blockcore Indexer (Release ${{env.VERSION}})"
tag: v${{env.VERSION}}
tag: ${{env.VERSION}}
21 changes: 0 additions & 21 deletions .github/workflows/docker.yml

This file was deleted.

67 changes: 0 additions & 67 deletions .github/workflows/publish.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Pull Request
on:
pull_request:
branches:
- master
- test3

jobs:

Expand Down
43 changes: 32 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
name: Release
name: Build and Release Docker Image

on:
release:
types: [published, prereleased]

jobs:

createRelease:
build:
name: Build and Push
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

strategy:
matrix:
os: [ ubuntu-latest ]
fail-fast: false
- name: Log Variables
run: |
echo "action - ${{ github.event.action }}"
echo "url - ${{ github.event.release.url }}"
echo "assets_url - ${{ github.event.release.assets_url }}"
echo "id - ${{ github.event.release.id }}"
echo "tag_name - ${{ github.event.release.tag_name }}"
echo "assets - ${{ github.event.assets }}"
echo "assets[0] - ${{ github.event.assets[0] }}"
runs-on: ${{ matrix.os }}

steps:
- uses: cschleiden/replace-tokens@v1
with:
files: '["**/Dockerfile.Release"]'
env:
VERSION: ${{ github.event.release.tag_name }}

- name: Build the Docker container image
run: docker build -f "./src/Blockcore.Indexer/Dockerfile.Release" -t blockcore/indexer:latest -t blockcore/indexer:${{ github.event.release.tag_name }} --label "unstable=true" "."

- name: Login and Push to Docker Registry
run: |
docker login -u "sondreb" -p "${{secrets.DockerHubSecret}}"
docker push blockcore/indexer
- uses: actions/checkout@v1
# - name: Login and Push to GitHub Docker Registry
# run: |
# docker login docker.pkg.github.com -u "blockcore-indexer" -p "${{secrets.GITHUB_TOKEN}}"
# docker push docker.pkg.github.com/block-core/blockcore-indexer/blockcoreindexer:latest
38 changes: 0 additions & 38 deletions .github/workflows/test.yml

This file was deleted.

1 change: 1 addition & 0 deletions Blockcore.Indexer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Indexer", "src\Bl
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BF780C62-90DC-466A-8936-6823D56707D4}"
ProjectSection(SolutionItems) = preProject
.dockerignore = .dockerignore
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
Expand Down
49 changes: 45 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

[5]: https://github.com/block-core/blockcore-indexer/actions
[6]: https://github.com/block-core/blockcore-indexer/workflows/Build/badge.svg
[7]: https://github.com/block-core/blockcore-indexer/workflows/Test/badge.svg
[8]: https://github.com/block-core/blockcore-indexer/workflows/Release/badge.svg
[9]: https://github.com/block-core/blockcore-indexer/workflows/Publish/badge.svg
[7]: https://github.com/block-core/blockcore-indexer/workflows/Release/badge.svg

[![Build Status][6]][5] [![Test Status][7]][5] [![Release Status][8]][5] [![Publish Packages Status][9]][5]
[![Build Status][6]][5] [![Release Status][7]][5]

Blockcore Indexer scans the blockchain of Blockcore-derived chains and stores transaction/address information in a MongoDB database with REST API available for Block Explorers to use.

Expand Down Expand Up @@ -39,3 +37,46 @@ GET /api/query/block/Index/{blockIndex}/{transactions}
GET /api/query/transaction/{transactionId}
GET /api/stats
GET /api/stats/peers


## Docker

```sh
docker build -t blockcoreindexer .
```

```sh
docker run -p 9901:9901 --name cityindexer blockcoreindexer:latest
```

```sh
// Run an individual chain from the docker sub-folders. Timeout should be high to avoid blockchain database storage issues.
docker-compose up --timeout 600
```

```sh
// Cleanup the majority of resources (doesn't delete volumes)
docker system prune -a
```
## Release Process
1. New changes to the codebase must come as pull requests. This will trigger the [pull-request.yml](.github/workflows/pull-request.yml) workflow.
2. When a pull request is merged to master, this will trigger [build.yml](.github/workflows/build.yml). Build will produce a draft release, or update existing.
3. After manual testing and verification of the draft release (which contains binaries created by build), a project responsible can release the draft release to the public, either as a release or pre-release.
4. The [release.yml](.github/workflows/release.yml) workflow picks up the release events, and builds the [docker image](src/Blockcore.Indexer/Dockerfile.Release) based on the newly released binary packages.
5. Newly built and released container can then be installed using either :latest tag (not adviseable) or the specific version (advised)
```sh
docker pull blockcore/indexer:latest
```
```sh
docker pull blockcore/indexer:0.0.3
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": {
"name": "Blockcore",
"email": "[email protected]",
"url": "http://www.blockcore.net"
"url": "https://www.blockcore.net"
},
"description": "",
"repository": {
Expand Down
16 changes: 2 additions & 14 deletions src/Blockcore.Indexer/Blockcore.Indexer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,20 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>Blockcore.Indexer</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>indexer.blockcore.net</PackageId>
<RuntimeFrameworkVersion>3.1.1</RuntimeFrameworkVersion>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<RootNamespace>Blockcore.Indexer</RootNamespace>
<UserSecretsId>7bd1d385-aa0f-4c2a-a842-f064d2cb4515</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<!--<DockerfileContext>..\..</DockerfileContext>-->
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>Blockcore.Indexer.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<Content Remove="wwwroot\index.html" />
</ItemGroup>

<ItemGroup>
<None Include="wwwroot\index.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.10" />
Expand Down
Loading

0 comments on commit adaf19f

Please sign in to comment.