Skip to content

Commit

Permalink
change Docker build action
Browse files Browse the repository at this point in the history
  • Loading branch information
ilhanu committed Feb 5, 2023
1 parent 5368d17 commit 86e247f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 34 deletions.
75 changes: 44 additions & 31 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,55 @@
name: docker-image-builder
# You need to add the following secrets to your GitHub Repository or Organization to make this work
# - DOCKER_USERNAME: The username of the DockerHub account. E.g. parity
# - DOCKER_TOKEN: Access token for DockerHub, see https://docs.docker.com/docker-hub/access-tokens/. E.g. VVVVVVVV-WWWW-XXXXXX-YYYY-ZZZZZZZZZ
# The following are setup as an environment variable below
# - DOCKER_REPO: The unique name of the DockerHub repository. E.g. parity/polkadot

name: Build & Publish Docker Image

# Controls when the action will run.
on:
push:
tags:
- v*
# Triggers the workflow on push events but only for the main branch
# push:
# branches: [ main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Set an environment variable (that can be overriden) for the Docker Repo
env:
IMAGE_NAME: fs-node
DOCKER_REPO: ilhanu/fs-node

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
docker:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- uses: actions/checkout@v3

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
build:
# The type of runner that the job will run on
runs-on: ubuntu-22.04

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Check out the repo
uses: actions/checkout@v2.5.0

# Login to Docker hub using the credentials stored in the repository secrets
- name: Log in to Docker Hub
uses: docker/login-action@v2.1.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

# Get the commit short hash, to use as the rev
- name: Calculate rev hash
id: rev
run: echo "value=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# 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_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
# Build and push 2 images, One with the version tag and the other with latest tag
- name: Build and push Docker images
uses: docker/build-push-action@v3.2.0
with:
context: .
push: true
tags: ${{ env.DOCKER_REPO }}:v${{ steps.rev.outputs.value }}, ${{ secrets.DOCKER_REPO }}:latest
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
FROM docker.io/paritytech/ci-linux:staging as builder
FROM docker.io/paritytech/ci-linux:production as builder

WORKDIR /substrate
COPY . /substrate
RUN cargo build --release --locked

FROM docker.io/library/ubuntu:20.04
LABEL org.opencontainers.image.source = "https://github.com/Fair-Squares/fair-squares"
LABEL description="Docker image for Fair Squares Node Software" \
image.source="https://github.com/Fair-Squares/fair-squares" \
image.authors="hello@fair-squares.nl" \
image.documentation="https://github.com/Fair-Squares/fair-squares" \
image.vendor="Fair Squares"

COPY --from=builder /substrate/target/release/fs-node /usr/local/bin

Expand All @@ -19,6 +23,6 @@ RUN useradd -m -u 1000 -U -s /bin/sh -d /fs fs && \

USER fs
EXPOSE 30333 9933 9944 9615
VOLUME ["/data"]
VOLUME ["/chain-data"]

CMD ["/usr/local/bin/fs-node"]

0 comments on commit 86e247f

Please sign in to comment.