Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Docker enhancements #1660

Merged
merged 17 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ on:
pull_request:
paths:
- ".github/workflows/build-docker.yml"
- "docker/centrifuge-chain/Dockerfile"
- "docker/centrifuge-chain"
- "docker/scripts"
- ".dockerignore"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}${{ github.event_name }}
cancel-in-progress: true
Expand All @@ -22,32 +24,50 @@ jobs:
target: [ release, test ]
runs-on: ubuntu-latest-8-cores
permissions:
contents: write
contents: write # to update the GH release w/ Docker tags
packages: write # to upload images to ghcr
id-token: write
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 #v3
- name: DockerHub Login
uses: docker/login-action@v3

- name: DockerHub Registry Login
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
lemunozm marked this conversation as resolved.
Show resolved Hide resolved
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- run: echo "NOW=$(date -u +%y-%m-%d)" >> $GITHUB_ENV
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated date according to standard RFC 3339 with full year instead of 2 digits

- name: Github Registry login
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- run: echo "NOW=$(date -u +%Y-%m-%d)" >> $GITHUB_ENV

- name: Setup docker metadata
id: meta
uses: docker/metadata-action@9dc751fe249ad99385a2583ee0d084c400eee04e #v5
with:
images: centrifugeio/centrifuge-chain
images: |
ghcr.io/centrifuge/centrifuge-chain
${{ github.event_name != 'pull_request' && 'centrifugeio/centrifuge-chain' || ''}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only push to DockerHub if it's not a PR

tags: |
type=semver,pattern={{raw}},prefix=${{ matrix.target == 'test' && 'test-' || '' }}
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
type=ref,event=tag,suffix=-{{sha}}-${{ env.NOW }},prefix=${{ matrix.target == 'test' && 'test-' || '' }}
type=ref,event=pr,suffix=-{{sha}}-${{ env.NOW }},prefix=${{ matrix.target == 'test' && 'test-' || '' }}PR
type=ref,event=branch,prefix=${{ matrix.target == 'test' && 'test-' || '' }},suffix=-{{sha}}-${{ env.NOW }}
labels: |
org.opencontainers.image.vendor="k-f dev AG" \
org.opencontainers.image.authors="[email protected]" \
org.opencontainers.image.documentation="https://github.com/centrifuge/centrifuge-chain/blob/main/README.md" \
org.opencontainers.image.base.name="ubuntu/jammy" \
org.opencontainers.image.base.digest="ubuntu@sha256:6042500cf4b44023ea1894effe7890666b0c5c7871ed83a97c36c76ae560bb9b"

- name: Configure GHA cache
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v6
Expand All @@ -63,7 +83,8 @@ jobs:
file: ./docker/centrifuge-chain/Dockerfile
build-args: |
FEATURES=${{ matrix.target == 'test' && 'fast-runtime' || '' }}
push: ${{ github.event_name != 'pull_request' }}
# Always push, either to ghcr or Dockerhub
push: true
gpmayorga marked this conversation as resolved.
Show resolved Hide resolved
tags: ${{ steps.meta.outputs.tags }}
# Cache options:
# https://docs.docker.com/build/ci/github-actions/cache/
Expand All @@ -82,14 +103,14 @@ jobs:
repository: centrifuge/centrifuge-chain
short-description: ${{ github.event.repository.description }}
enable-url-completion: true

- name: Update GitHub release
if: github.event_name == 'release' && matrix.target == 'release'
uses: softprops/action-gh-release@v1
with:
append_body: true
body: |
**Docker tags:**
**Docker tags:**
${{ steps.meta.outputs.tags }}

- if: failure()
Expand Down
37 changes: 17 additions & 20 deletions docker/centrifuge-chain/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,40 @@ FROM --platform=linux/amd64 docker.io/paritytech/ci-linux:production as builder
# and simply download the binaries here. Some short of hash or integrity check would need to
# happen to make sure the binary is what we want.
FROM --platform=linux/amd64 docker.io/library/ubuntu:jammy
ARG BUILD_DATE
ARG VERSION

LABEL io.centrifuge.image.authors="[email protected]" \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LABELS are set using the GHA pipleline on the metadata step.
Ideally we don't publish images from our laptops and thus no need to have this here

io.centrifuge.image.vendor="Centrifuge" \
io.centrifuge.image.title="centrifugeio/centrifuge-chain" \
io.centrifuge.image.description="Centrifuge, the layer 1 of RWA. This is the official Centrifuge (para)chain image" \
io.centrifuge.image.source="https://github.com/centrifuge/centrifuge-chain/blob/main/docker/centrifuge-chain/Dockerfile" \
io.centrifuge.image.created="${BUILD_DATE}"

# Add chain resources to image
COPY node/res /resources/

COPY --from=builder /centrifuge-chain/target/release/centrifuge-chain /usr/local/bin

RUN apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* ;
RUN apt-get update && apt-get install -y curl jq
RUN apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/*

# Because of the following, all data and config directories need to be owned by UID and GID 1000
RUN useradd -m -u 1000 -U -s /bin/sh -d /centrifuge centrifuge

COPY node/res /resources/
COPY --from=builder /centrifuge-chain/target/release/centrifuge-chain /usr/local/bin/

COPY docker/scripts /centrifuge/scripts
# The following will make everything under /centrifuge/scripts reachable from PATH
# by creating a symbolic link into /usr/local/bin
RUN chmod +x /centrifuge/scripts/* && \
ln -s /centrifuge/scripts/* /usr/local/bin/

RUN mkdir -p /data && \
RUN mkdir -p /data && \
chown -R centrifuge:centrifuge /data && \
chown -R centrifuge:centrifuge /resources && \
chown -R centrifuge:centrifuge /usr/local/bin/centrifuge-chain && \
chown -R centrifuge:centrifuge /centrifuge/

COPY ./docker/scripts/entrypoint.sh /centrifuge/entrypoint.sh
RUN chown -R centrifuge:centrifuge /centrifuge/entrypoint.sh && chmod +x /centrifuge/entrypoint.sh
chown -R centrifuge:centrifuge /centrifuge/

# Running as an non-root is a good security practice
# in some cases the container can be forced to run as root overriding the next line
# but by default we want to enforce this.
USER centrifuge
WORKDIR /centrifuge

# checks
RUN ldd /usr/local/bin/centrifuge-chain && \
/usr/local/bin/centrifuge-chain --version

EXPOSE 30333 9933 9944
VOLUME ["/data"]
ENTRYPOINT ["/centrifuge/entrypoint.sh"]
ENTRYPOINT ["entrypoint.sh"]
CMD ["--help"]