diff --git a/.dockerignore b/.dockerignore index f6f1a832f..aa66cbcb3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,6 +3,7 @@ target integration_tests/blockstack-consensus-data/ integration_tests/test-out/ api/data +.git .venv .dockerignore testnet/index.html diff --git a/.github/workflows/stacks-blockchain.yml b/.github/workflows/stacks-blockchain.yml index 0267b8655..2901e07f3 100644 --- a/.github/workflows/stacks-blockchain.yml +++ b/.github/workflows/stacks-blockchain.yml @@ -1,14 +1,10 @@ name: stacks-blockchain # Only run when: -# - tags starting with "v" get pushed # - PRs are opened against the master branch # - the workflow is started from the UI (an optional tag can be passed in via parameter) # - If the optional tag parameter is passed in, a new tag will be generated based off the selected branch on: - push: - tags: - - 'v*' pull_request: workflow_dispatch: inputs: @@ -58,7 +54,6 @@ jobs: # Run net-tests nettest: runs-on: ubuntu-latest - if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v') steps: - uses: actions/checkout@v2 - name: Run network relay tests @@ -109,6 +104,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Set Vars + run: | + echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV + echo "GITHUB_REF_SHORT=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + - name: Build/Tag/Push Image uses: docker/build-push-action@v1 with: @@ -118,8 +118,9 @@ jobs: tags: ${{ github.event.inputs.tag }} tag_with_ref: true add_git_labels: true - # Only push if (a tag was passed in) or (we're building a tag) or (we're building a non-master branch which isn't a PR) - push: ${{ github.event.inputs.tag != '' || contains(github.ref, 'refs/tags') || (github.ref != 'refs/heads/master' && !contains(github.ref, 'refs/pull')) }} + build_args: STACKS_NODE_VERSION=${{ github.event.inputs.tag || env.GITHUB_SHA_SHORT }},GIT_BRANCH=${{ env.GITHUB_REF_SHORT }},GIT_COMMIT=${{ env.GITHUB_SHA_SHORT }} + # Only push if (a tag was passed in) or (we're building a non-master branch which isn't a PR) + push: ${{ github.event.inputs.tag != '' || (github.ref != 'refs/heads/master' && !contains(github.ref, 'refs/pull')) }} # Build docker image, tag it with the git tag and `latest` if running on master branch, and publish under the following conditions # Will publish if: @@ -146,6 +147,11 @@ jobs: env: TAG: ${{ github.event.inputs.tag }} + - name: Set Vars + run: | + echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV + echo "GITHUB_REF_SHORT=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + - name: Build/Tag/Push Image uses: docker/build-push-action@v1 with: @@ -156,13 +162,14 @@ jobs: tags: ${{ env.STRETCH_TAG }} tag_with_ref: false add_git_labels: true - # Only push if (a tag was passed in) or (we're building a tag) or (we're building a non-master branch which isn't a PR) - push: ${{ github.event.inputs.tag != '' || contains(github.ref, 'refs/tags') || (github.ref != 'refs/heads/master' && !contains(github.ref, 'refs/pull')) }} + build_args: STACKS_NODE_VERSION=${{ github.event.inputs.tag || env.GITHUB_SHA_SHORT }},GIT_BRANCH=${{ env.GITHUB_REF_SHORT }},GIT_COMMIT=${{ env.GITHUB_SHA_SHORT }} + # Only push if (a tag was passed in) or (we're building a non-master branch which isn't a PR) + push: ${{ github.event.inputs.tag != '' || (github.ref != 'refs/heads/master' && !contains(github.ref, 'refs/pull')) }} - # Create a new release if we're building a tag or a tag was passed in + # Create a new release if we're building a tag create-release: runs-on: ubuntu-latest - if: ${{ github.event.inputs.tag != '' || contains(github.ref, 'refs/tags') }} + if: ${{ github.event.inputs.tag != '' }} outputs: upload_url: ${{ steps.create_release.outputs.upload_url }} needs: @@ -187,7 +194,7 @@ jobs: # Upload distributables to a new release if we're building a tag or a tag was passed in upload-dist: runs-on: ubuntu-latest - if: ${{ github.event.inputs.tag != '' || contains(github.ref, 'refs/tags') }} + if: ${{ github.event.inputs.tag != '' }} needs: - create-release strategy: diff --git a/Dockerfile b/Dockerfile index 2457f5803..3b4222083 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,9 @@ FROM rust:alpine as build +ARG STACKS_NODE_VERSION="No Version Info" +ARG GIT_BRANCH='No Branch Info' +ARG GIT_COMMIT='No Commit Info' + WORKDIR /src COPY . . @@ -18,4 +22,4 @@ FROM alpine COPY --from=build /out/ /bin/ -CMD ["stacks-node", "argon"] +CMD ["stacks-node", "xenon"] diff --git a/Dockerfile.stretch b/Dockerfile.stretch index 76a6009b0..eefa85d21 100644 --- a/Dockerfile.stretch +++ b/Dockerfile.stretch @@ -1,5 +1,9 @@ FROM rust:stretch as build +ARG STACKS_NODE_VERSION="No Version Info" +ARG GIT_BRANCH='No Branch Info' +ARG GIT_COMMIT='No Commit Info' + WORKDIR /src COPY . . @@ -17,4 +21,4 @@ FROM debian:stretch-slim RUN apt update && apt install -y netcat COPY --from=build /out/ /bin/ -CMD ["stacks-node", "argon"] +CMD ["stacks-node", "xenon"] diff --git a/build.rs b/build.rs index 4ff4d06b4..d64ccb22f 100644 --- a/build.rs +++ b/build.rs @@ -1,32 +1,42 @@ use std::process::Command; fn current_git_hash() -> Option { - let commit = Command::new("git") - .arg("log") - .arg("-1") - .arg("--pretty=format:%h") // Abbreviated commit hash - .current_dir(env!("CARGO_MANIFEST_DIR")) - .output(); + if option_env!("GIT_COMMIT") == None { + let commit = Command::new("git") + .arg("log") + .arg("-1") + .arg("--pretty=format:%h") // Abbreviated commit hash + .current_dir(env!("CARGO_MANIFEST_DIR")) + .output(); - if let Ok(commit) = commit { - if let Ok(commit) = String::from_utf8(commit.stdout) { - return Some(commit); + if let Ok(commit) = commit { + if let Ok(commit) = String::from_utf8(commit.stdout) { + return Some(commit); + } } + } else { + return option_env!("GIT_COMMIT").map(String::from); } + None } fn current_git_branch() -> Option { - let commit = Command::new("git") - .arg("rev-parse") - .arg("--abbrev-ref") - .arg("HEAD") - .output(); - if let Ok(commit) = commit { - if let Ok(commit) = String::from_utf8(commit.stdout) { - return Some(commit); + if option_env!("GIT_BRANCH") == None { + let commit = Command::new("git") + .arg("rev-parse") + .arg("--abbrev-ref") + .arg("HEAD") + .output(); + if let Ok(commit) = commit { + if let Ok(commit) = String::from_utf8(commit.stdout) { + return Some(commit); + } } + } else { + return option_env!("GIT_BRANCH").map(String::from); } + None } diff --git a/src/lib.rs b/src/lib.rs index e56fc125d..1482d552e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,16 +96,15 @@ const BUILD_TYPE: &'static str = "release"; pub fn version_string(pkg_name: &str, pkg_version: &str) -> String { let git_branch = GIT_BRANCH - .map(|x| format!("{}:", x)) + .map(|x| format!("{}", x)) .unwrap_or("".to_string()); let git_commit = GIT_COMMIT.unwrap_or(""); let git_tree_clean = GIT_TREE_CLEAN.unwrap_or(""); format!( - "{} {} => {} ({}{}{}, {} build, {} [{}])", + "{} {} ({}:{}{}, {} build, {} [{}])", pkg_name, pkg_version, - core::CHAINSTATE_VERSION, &git_branch, git_commit, git_tree_clean, diff --git a/src/net/rpc.rs b/src/net/rpc.rs index d51169d7a..0eeee5e39 100644 --- a/src/net/rpc.rs +++ b/src/net/rpc.rs @@ -187,8 +187,10 @@ impl RPCPeerInfoData { }; let server_version = version_string( - option_env!("CARGO_PKG_NAME").unwrap_or("stacks-node"), - option_env!("CARGO_PKG_VERSION").unwrap_or("0.0.0.0"), + "stacks-node", + option_env!("STACKS_NODE_VERSION") + .or(option_env!("CARGO_PKG_VERSION")) + .unwrap_or("0.0.0.0"), ); let stacks_tip_consensus_hash = burnchain_tip.canonical_stacks_tip_consensus_hash; let stacks_tip = burnchain_tip.canonical_stacks_tip_hash; diff --git a/testnet/stacks-node/src/main.rs b/testnet/stacks-node/src/main.rs index ea0dcd07b..487cde030 100644 --- a/testnet/stacks-node/src/main.rs +++ b/testnet/stacks-node/src/main.rs @@ -116,8 +116,10 @@ fn main() { println!( "{}", &stacks::version_string( - option_env!("CARGO_PKG_NAME").unwrap_or("stacks-node"), - option_env!("CARGO_PKG_VERSION").unwrap_or("0.0.0.0") + "stacks-node", + option_env!("STACKS_NODE_VERSION") + .or(option_env!("CARGO_PKG_VERSION")) + .unwrap_or("0.0.0.0") ) ); return;