Skip to content

Commit

Permalink
ci: fix Dockerfile and add docker image release job (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 authored Feb 6, 2023
1 parent b983cb8 commit d930ab8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
2 changes: 0 additions & 2 deletions .github/generate_change_log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ while read line; do
done < ${change_log_file}
LINUX_BIN_SUM="$(checksum ./linux/linux)"
MAC_BIN_SUM="$(checksum ./macos/macos)"
WINDOWS_BIN_SUM="$(checksum ./windows/windows.exe)"
OUTPUT=$(cat <<-END
${CHANGE_LOG}\n
## Assets\n
| Assets | Sha256 Checksum |\n
| :-----------: |------------|\n
| linux | ${LINUX_BIN_SUM} |\n
| mac | ${MAC_BIN_SUM} |\n
| windows | ${WINDOWS_BIN_SUM} |\n
END
)

Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Docker

on:
push:
# Publish `v1.2.3` tags as releases.
tags:
- v*

env:
IMAGE_NAME: ghcr.io/bnb-chain/greenfield
IMAGE_SOURCE: https://github.com/bnb-chain/greenfield

jobs:
# Push image to GitHub Packages.
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v3

- name: Build image
run: |
docker build . \
--build-arg "GH_TOKEN=${{ secrets.GH_ACCESS_SECRET }}" \
--label "org.opencontainers.image.source=${IMAGE_SOURCE}" \
--label "org.opencontainers.image.revision=$(git rev-parse HEAD)" \
--label "org.opencontainers.image.version=$(git describe --tags --abbrev=0)" \
--label "org.opencontainers.image.licenses=LGPL-3.0,GPL-3.0" \
-f ./Dockerfile -t "${IMAGE_NAME}"
- name: Log into registry
run: echo "${{ secrets.GH_ACCESS_SECRET }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_NAME=$IMAGE_NAME
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_NAME:$VERSION
docker tag $IMAGE_NAME $IMAGE_NAME:latest
docker push $IMAGE_NAME:$VERSION
docker push $IMAGE_NAME:latest
20 changes: 14 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
FROM golang:1.18-alpine as builder

RUN apk add --no-cache make git bash
RUN apk add --no-cache make git bash build-base linux-headers libc-dev

ADD . /greenfield

ENV CGO_ENABLED=0
ENV CGO_ENABLED=1
ENV GO111MODULE=on

# For Private REPO
ARG GH_TOKEN=""
RUN go env -w GOPRIVATE="github.com/bnb-chain/*"
RUN git config --global url."https://${GH_TOKEN}@github.com".insteadOf "https://github.com"

RUN cd /greenfield && make build

# Pull greenfield into a second stage deploy alpine container
FROM alpine:3.16
FROM alpine:3.17

ARG USER=greenfield
ARG USER_UID=1000
ARG USER_GID=1000

ENV CGO_CFLAGS="-O -D__BLST_PORTABLE__"
ENV CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__"

ENV PACKAGES ca-certificates bash curl libstdc++
ENV WORKDIR=/server
ENV WORKDIR=/app

RUN apk add --no-cache $PACKAGES \
&& rm -rf /var/cache/apk/* \
Expand All @@ -30,10 +38,10 @@ RUN echo "[ ! -z \"\$TERM\" -a -r /etc/motd ] && cat /etc/motd" >> /etc/bash/bas

WORKDIR ${WORKDIR}

COPY --from=builder /greenfield/build/bin/greenfieldd ${WORKDIR}/
COPY --from=builder /greenfield/build/bin/gnfd ${WORKDIR}/
RUN chown -R ${USER_UID}:${USER_GID} ${WORKDIR}
USER ${USER_UID}:${USER_GID}

EXPOSE 26656 26657 9090 1317 6060 4500

ENTRYPOINT ["/server/greenfieldd"]
ENTRYPOINT ["/app/gnfd"]

0 comments on commit d930ab8

Please sign in to comment.