Skip to content

Commit

Permalink
build: fixing building in docker container (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
Woosang Son authored Apr 5, 2021
1 parent 2b5e16c commit 4bc528a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 58 deletions.
97 changes: 49 additions & 48 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build & Push
# Build & Push rebuilds the ostracon docker image on every push to master and creation of tags
# and pushes the image to https://http://docker-registry.linecorp.com/link-network/v2/lbm
# and pushes the image to https://docker-registry.linecorp.com/link-network/v2/lbm
on:
pull_request:
push:
Expand All @@ -11,50 +11,51 @@ on:
- "v[0-9]+.[0-9]+.[0-9]+-rc*" # Push events to matching v*, i.e. v1.0-rc1, v20.15.10-rc5

jobs:
# TODO ebony: enable docker build
# build:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@master
# - name: Prepare
# id: prep
# run: |
# DOCKER_IMAGE=ostracon/ostracon
# VERSION=noop
# if [[ $GITHUB_REF == refs/tags/* ]]; then
# VERSION=${GITHUB_REF#refs/tags/}
# elif [[ $GITHUB_REF == refs/heads/* ]]; then
# VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
# if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
# VERSION=latest
# fi
# fi
# TAGS="${DOCKER_IMAGE}:${VERSION}"
# if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
# TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}"
# fi
# echo ::set-output name=tags::${TAGS}
#
# - name: Set up QEMU
# uses: docker/setup-qemu-action@master
# with:
# platforms: all
#
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1
#
# - name: Login to DockerHub
# if: ${{ github.event_name != 'pull_request' }}
# uses: docker/login-action@v1
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
#
# - name: Publish to Docker Hub
# uses: docker/build-push-action@v2
# with:
# context: .
# file: ./DOCKER/Dockerfile
# platforms: linux/amd64,linux/arm64
# push: ${{ github.event_name != 'pull_request' }}
# tags: ${{ steps.prep.outputs.tags }}
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=ostracon/ostracon
VERSION=noop
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=latest
fi
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}"
fi
echo ::set-output name=tags::${TAGS}
- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: all

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Publish to Docker Hub
uses: docker/build-push-action@v2
with:
context: .
file: ./DOCKER/Dockerfile
platforms: linux/amd64,linux/arm64
build-args: |
GITHUB_TOKEN=${{ secrets.TOKEN }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
13 changes: 7 additions & 6 deletions DOCKER/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# stage 1 Generate Tendermint Binary
# stage 1 Generate Ostracon Binary
FROM golang:1.15-alpine as builder
ARG GITHUB_TOKEN=""
RUN apk update && \
apk upgrade && \
apk --no-cache add make git
COPY / /ostracon
WORKDIR /ostracon
RUN git config --global url."https://${TOKEN}:x-oauth-basic@github.com".insteadOf "https://github.com"
RUN go env -w GOPRIVATE=github.com/line/*
RUN git config --global url."https://$GITHUB_TOKEN:x-oauth-basic@github.com".insteadOf "https://github.com"
RUN go mod download
RUN make build-linux

# stage 2
FROM golang:1.15-alpine
LABEL maintainer="hello@ostracon.com"
LABEL maintainer="ostracon@linecorp.com"

# Tendermint will be looking for the genesis file in /ostracon/config/genesis.json
# Ostracon will be looking for the genesis file in /ostracon/config/genesis.json
# (unless you change `genesis_file` in config.toml). You can put your config.toml and
# private validator file into /ostracon/config.
#
Expand Down Expand Up @@ -42,14 +44,13 @@ EXPOSE 26656 26657 26660
STOPSIGNAL SIGTERM

COPY --from=builder /ostracon/build/ostracon /usr/bin/ostracon
COPY --from=builder /ostracon/DOCKER/docker-entrypoint.sh /usr/local/bin/

# You can overwrite these before the first run to influence
# config.json and genesis.json. Additionally, you can override
# CMD to add parameters to `ostracon node`.
ENV PROXY_APP=kvstore MONIKER=dockernode CHAIN_ID=dockerchain

COPY ./DOCKER/docker-entrypoint.sh /usr/local/bin/

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["node"]

Expand Down
6 changes: 3 additions & 3 deletions DOCKER/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
set -e

if [ ! -d "$TMHOME/config" ]; then
echo "Running tendermint init to create (default) configuration for docker run."
tendermint init
echo "Running ostracon init to create (default) configuration for docker run."
ostracon init

sed -i \
-e "s/^proxy_app\s*=.*/proxy_app = \"$PROXY_APP\"/" \
Expand All @@ -20,4 +20,4 @@ if [ ! -d "$TMHOME/config" ]; then
mv "$TMHOME/config/genesis.json.new" "$TMHOME/config/genesis.json"
fi

exec tendermint "$@"
exec ostracon "$@"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ sync-docs:

build-docker: build-linux
cp $(OUTPUT) DOCKER/ostracon
docker build --label=ostracon --tag="ostracon/ostracon" DOCKER
docker build --build-arg GITHUB_TOKEN=$(GITHUB_TOKEN) --label=ostracon --tag="ostracon/ostracon" --file ./DOCKER/Dockerfile .
rm -rf DOCKER/ostracon
.PHONY: build-docker

Expand Down

0 comments on commit 4bc528a

Please sign in to comment.