Skip to content

Commit

Permalink
feat: Workflow to publish the docker image on a release
Browse files Browse the repository at this point in the history
  • Loading branch information
robvanmieghem committed Jan 13, 2023
1 parent 7a662c7 commit c242557
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Workflows

This page contains some documentation on the workflows for this repository.

## build_test

The workflow build_test is used to build and test the code (see build_test.yaml). Notice that the binaries are being cached so that the build process is sped up. Once the binaries are build the pipeline will run both the unit tests and the integration tests. This can take up to 30 minutes. The pipeline is ran on every commit to a PR and also when the PR has been merged with development. PRs should only be merged if the pipeline was green (if all tests passed).

For performance reasons we are using a self hosted runner for running the pipeline. The runner will only run one pipeline at a time which means that all other runs will be queued. As the pipeline is ran on every commit it will thus also queue runs of consecutive pushed commits. We strongly advice to add `[skip ci]` to the commit messages whenever possible (when the run of a pipeline can be skipped). A pipeline can also be canceled [here](https://github.com/threefoldtech/tfchain/actions).
For performance reasons we are using a self hosted runner for running the pipeline. The runner will only run one pipeline at a time which means that all other runs will be queued. As the pipeline is ran on every commit it will thus also queue runs of consecutive pushed commits. We strongly advice to add `[skip ci]` to the commit messages whenever possible (when the run of a pipeline can be skipped). A pipeline can also be canceled [here](https://github.com/threefoldtech/tfchain/actions).

### Docker image

We are using a custom docker image for building and testing the code. You can find the image on our [Docker Hub](https://hub.docker.com/repository/docker/threefolddev/tfchain). The dockerfile build_test.Dockerfile was used to build that image. If the image no longer meets the expectations please follow these steps:

1) Update the dockerfile as required (add what you need)
Expand All @@ -18,8 +21,11 @@ We are using a custom docker image for building and testing the code. You can fi
4) Upload the image (you will need the credentials):
> docker login
> docker push threefolddev/tfchain:\<VERSION>
5) Update the pipeline on the repository https://github.com/threefoldtech/tfchain under .github/workflows to use this new image
5) Update the pipeline on the repository <https://github.com/threefoldtech/tfchain> under .github/workflows to use this new image
6) Push your changes, create a PR and let the pipeline run. If it fails due to changes to the image you should start over the steps.
7) Once the PR is landed please tag the repository so that we can trace back the dockerfile given the version:
> git tag -a dockerfile-build-v\<VERSION> -m "new dockerfile version \<VERSION>"
## Publishing of a docker image

[publish_container_image.yml](./publish_container_image.yml) builds the docker container of a tfchain node and publishes it to the github container repository on a release.
39 changes: 39 additions & 0 deletions .github/workflows/publish_container_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Publish Docker image

on:
release:
types: [published]

jobs:
build-and-push:
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write

steps:
- name: Checkout the repo
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v2.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
push: true
context: ./substrate-node
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
3 changes: 2 additions & 1 deletion substrate-node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ RUN ldd /usr/local/bin/tfchain && \

# Install CA certificates not present in base image
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y ca-certificates
# curl is a handy tool when you need to make an rpc call inside the container
RUN apt-get install -y curl

# Shrinking
RUN rm -rf /usr/lib/python* && \
Expand Down

0 comments on commit c242557

Please sign in to comment.