Skip to content

Commit

Permalink
Merge branch 'github-actions'
Browse files Browse the repository at this point in the history
  • Loading branch information
doitian committed Jul 4, 2021
2 parents 4d4058f + 127baf7 commit a5128ac
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 134 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Docker

on:
push:
branches:
- master
tags:
- "*"

jobs:
build:
name: Build
runs-on: ubuntu-latest

strategy:
matrix:
distro: [centos-7, bionic]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up docker buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest

- name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.CR_USERNAME }}
password: ${{ secrets.CR_PAT }}

- name: Build
uses: docker/build-push-action@v2
with:
file: ${{ matrix.distro }}/Dockerfile
context: .
push: true
tags: ghcr.io/nervosnetwork/ckb-docker-builder:${{ matrix.distro }}-${{ github.sha }}

test:
name: Test
runs-on: ubuntu-latest
needs: build

strategy:
matrix:
distro: [centos-7, bionic]

steps:
- name: Checkout CKB
uses: actions/checkout@v2
with:
repository: nervosnetwork/ckb
path: ckb

- name: Build CKB
run: |
docker run --rm -i -w /ckb -v $(pwd)/ckb:/ckb ghcr.io/nervosnetwork/ckb-docker-builder:${{ matrix.distro }}-${{ github.sha }} make prod
publish:
name: Publish
runs-on: ubuntu-latest
needs: test
if: ${{ startsWith(github.ref, 'refs/tags/') }}

strategy:
matrix:
distro: [centos-7, bionic]

steps:
- name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.CR_USERNAME }}
password: ${{ secrets.CR_PAT }}

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Determine tag
id: tag
run: echo "::set-output name=tag::${GITHUB_REF##*/}"

- name: Tag and push image
uses: akhilerm/[email protected]
with:
src: ghcr.io/nervosnetwork/ckb-docker-builder:${{ matrix.distro }}-${{ github.sha }}
dst: |
ghcr.io/nervosnetwork/ckb-docker-builder:${{ matrix.distro }}-latest
ghcr.io/nervosnetwork/ckb-docker-builder:${{ matrix.distro }}-${{ steps.tag.outputs.tag }}
nervos/ckb-docker-builder:${{ matrix.distro }}-latest
nervos/ckb-docker-builder:${{ matrix.distro }}-${{ github.event.inputs.tag }}
16 changes: 16 additions & 0 deletions .github/workflows/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Template Test

on:
pull_request:
push:
branches:
- "*"

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: python3 gen-dockerfiles
- run: git diff --exit-code

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/ckb
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
DOCKERHUB_REPO := nervos/ckb-docker-builder
GHCR_REPO := ghcr.io/nervosnetwork/ckb-docker-builder
IMAGE_VERSION := rust-$(shell sed -n "s/RUST_VERSION = '\(.*\)'$$/\1/p" gen-dockerfiles)

bionic/Dockerfile: gen-dockerfiles templates/bionic.Dockerfile
python3 gen-dockerfiles

centos-7/Dockerfile: gen-dockerfiles templates/centos-7.Dockerfile
python3 gen-dockerfiles

build-all: build-bionic build-centos-7

build-bionic: bionic/Dockerfile
docker build -f bionic/Dockerfile --tag ${DOCKERHUB_REPO}:bionic-${IMAGE_VERSION} .

build-centos-7: centos-7/Dockerfile
docker build -f centos-7/Dockerfile --tag ${DOCKERHUB_REPO}:centos-7-${IMAGE_VERSION} .

.PHONY: build-all build-bionic build-centos-7

push-all: push-bionic push-centos-7

push-bionic: build-bionic
docker push ${DOCKERHUB_REPO}:bionic-${IMAGE_VERSION}

push-centos-7: build-centos-7
docker push ${DOCKERHUB_REPO}:centos-7-${IMAGE_VERSION}

.PHONY: push-all push-bionic push-centos-7

test-all: test-bionic test-centos-7

sync-ckb:
if [ -d ckb ]; then git -C ckb pull; else git clone --depth 1 https://github.com/nervosnetwork/ckb.git; fi

test-bionic: sync-ckb
docker --rm -it -w /ckb -v "$$(pwd)/ckb:/ckb" ${DOCKERHUB_REPO}:bionic-${IMAGE_VERSION} make prod

test-centos-7: sync-ckb
docker --rm -it -w /ckb -v "$$(pwd)/ckb:/ckb" ${DOCKERHUB_REPO}:centos-7-${IMAGE_VERSION} make prod

.PHONY: test-all test-bionic test-centos-7 sync-ckb
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Environment for building [ckb](https://github.com/nervosnetwork/ckb#readme).
- Update rustup version if needed in [`gen-dockerfiles`].
- Update rust version in [`gen-dockerfiles`].
- Run the script [`gen-dockerfiles`].
- Commit and tag `rust-${RUST_VERSION}` such as `rust-1.38.0`.
- Commit, tag `rust-${RUST_VERSION}` such as `rust-1.51.0`.

[`gen-dockerfiles`]: gen-dockerfiles
5 changes: 2 additions & 3 deletions bionic/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
g++ \
gcc \
g++ \
libc6-dev \
wget \
libssl-dev \
git \
pkg-config \
libclang-dev clang; \
pkg-config; \
rm -rf /var/lib/apt/lists/*

ENV RUSTUP_HOME=/usr/local/rustup \
Expand Down
7 changes: 6 additions & 1 deletion centos-7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV PATH=/root/.cargo/bin:$PATH

RUN set -eux; \
yum install -y centos-release-scl; \
yum install -y git curl make gcc-c++ openssl-devel llvm-toolset-7; \
yum install -y git curl make openssl-devel devtoolset-7; \
yum clean all; \
rm -rf /var/cache/yum

Expand All @@ -30,3 +30,8 @@ RUN set -eux; \
rustup --version; \
cargo --version; \
rustc --version;

COPY centos-7/entrypoint.sh /

ENTRYPOINT ["/entrypoint.sh"]
CMD ["bash"]
3 changes: 3 additions & 0 deletions centos-7/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

scl enable devtoolset-7 "$*"
2 changes: 1 addition & 1 deletion gen-dockerfiles
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUST_ARCH = 'x86_64-unknown-linux-gnu'

DISTRIBUTIONS = [
# Ubuntu
'xenial', 'bionic',
'bionic',
# CentOS
'centos-7',
]
Expand Down
4 changes: 2 additions & 2 deletions templates/bionic.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ RUN set -eux; \
apt-get install -y --no-install-recommends \
ca-certificates \
gcc \
g++ \
libc6-dev \
wget \
libssl-dev \
git \
pkg-config \
libclang-dev clang; \
pkg-config; \
rm -rf /var/lib/apt/lists/*

ENV RUSTUP_HOME=/usr/local/rustup \
Expand Down
7 changes: 6 additions & 1 deletion templates/centos-7.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV PATH=/root/.cargo/bin:$PATH

RUN set -eux; \
yum install -y centos-release-scl; \
yum install -y git curl make gcc-c++ openssl-devel llvm-toolset-7; \
yum install -y git curl make openssl-devel devtoolset-7; \
yum clean all; \
rm -rf /var/cache/yum

Expand All @@ -30,3 +30,8 @@ RUN set -eux; \
rustup --version; \
cargo --version; \
rustc --version;

COPY centos-7/entrypoint.sh /

ENTRYPOINT ["/entrypoint.sh"]
CMD ["bash"]
52 changes: 0 additions & 52 deletions templates/xenial.Dockerfile

This file was deleted.

73 changes: 0 additions & 73 deletions xenial/Dockerfile

This file was deleted.

0 comments on commit a5128ac

Please sign in to comment.