Skip to content

Commit 8510030

Browse files
authored
[CI/Containers] Add image build workflow (#1557)
## Description With our decision to switch to GitHub Packages as the Container Registry for v0, it becomes easier to use the workflow to push the image. To ensure a seamless transition, I have used an existing multi-arch build as a base. This means that existing deployments should not be affected or break due to the changes. To validate the compatibility, I conducted tests on my own node by replacing the `poktnetwork/pocket-core:RC-0.9.2` image with the one generated by this workflow. The tests indicated that everything functioned as expected, without any issues. Registry link: https://github.com/pokt-network/pocket-core/pkgs/container/pocket-v0 <!-- reviewpad:summarize:start --> ### Summary generated by Reviewpad on 07 Jun 23 22:17 UTC This pull request adds an image build workflow, with a Dockerfile, build-images.yaml, and entrypoint.sh. The workflow handles build and push of images to GitHub Container Registry, while staging is set as the main branch. Additionally, the patch checks if it works with PR events. <!-- reviewpad:summarize:end -->
1 parent b515c1d commit 8510030

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed

.github/workflows/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Based on a previous implementation to make sure we don't break existing deployments.
2+
# https://github.com/pokt-network/pocket-core-deployments/blob/staging/docker/Dockerfile
3+
4+
FROM golang:1.17-alpine as build
5+
RUN apk add --no-cache ca-certificates
6+
WORKDIR /build
7+
ADD . .
8+
RUN go build -o pocket app/cmd/pocket_core/main.go
9+
10+
FROM alpine
11+
RUN apk add --update --no-cache expect bash leveldb-dev tzdata && cp /usr/share/zoneinfo/America/New_York /etc/localtime \
12+
&& addgroup --gid 1001 -S app \
13+
&& adduser --uid 1005 -S -G app app
14+
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
15+
COPY --from=build /build/pocket /bin/pocket
16+
COPY .github/workflows/entrypoint.sh /home/app/entrypoint.sh
17+
RUN chown -R app /bin/pocket && mkdir -p /home/app/.pocket/config && chown -R app /home/app/.pocket
18+
ENTRYPOINT ["/usr/bin/expect", "/home/app/entrypoint.sh"]

.github/workflows/build-images.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This workflow only handles build & push of images to GitHub Container Registry.
2+
# We have other pipepines in CircleCI, such as tests, that are not migrated to GitHub Actions.
3+
4+
name: Build and push images
5+
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches: [staging]
10+
pull_request:
11+
branches: [staging]
12+
release:
13+
types: [published]
14+
15+
jobs:
16+
build-images:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Docker Setup QEMU
21+
uses: docker/setup-qemu-action@v2
22+
- name: Docker Setup Buildx
23+
uses: docker/setup-buildx-action@v2
24+
- name: Docker Metadata action
25+
id: meta
26+
uses: docker/metadata-action@v4
27+
env:
28+
DOCKER_METADATA_PR_HEAD_SHA: "true"
29+
with:
30+
images: |
31+
ghcr.io/pokt-network/pocket-v0
32+
tags: |
33+
type=schedule
34+
type=semver,pattern={{raw}}
35+
type=ref,event=branch
36+
type=ref,event=pr
37+
type=sha
38+
type=sha,format=long
39+
type=raw,value=latest,enable={{is_default_branch}}
40+
- name: Login to GitHub Container Registry
41+
uses: docker/login-action@v2
42+
with:
43+
registry: ghcr.io
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
- name: Build and push Docker image
47+
uses: docker/build-push-action@v3
48+
with:
49+
push: true
50+
tags: ${{ steps.meta.outputs.tags }}
51+
labels: ${{ steps.meta.outputs.labels }}
52+
platforms: linux/amd64,linux/arm64
53+
file: .github/workflows/Dockerfile
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max

.github/workflows/entrypoint.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/expect
2+
3+
# Send `pocket stop` when interrupted to prevent corruption
4+
proc graceful_exit {} {
5+
send_user "Gracefully exiting Pocket...\n"
6+
spawn sh -c "pocket stop"
7+
}
8+
9+
trap graceful_exit {SIGINT SIGTERM}
10+
11+
# Command to run
12+
set command $argv
13+
set timeout -1
14+
15+
# Create work dir
16+
spawn sh -c "mkdir -p /home/app/.pocket/config"
17+
expect eof
18+
19+
# Pull variables from env if set
20+
set genesis ""
21+
catch {set genesis $env(POCKET_CORE_GENESIS)}
22+
23+
set chains ""
24+
catch {set chains $env(POCKET_CORE_CHAINS)}
25+
26+
set config ""
27+
catch {set config $env(POCKET_CORE_CONFIG)}
28+
29+
# Create dynamic config files
30+
if {$genesis != ""} {
31+
set genesis_file [open /home/app/.pocket/config/genesis.json w]
32+
puts $genesis_file $genesis
33+
close $genesis_file
34+
send_user "GENESIS loaded from env\n"
35+
}
36+
if {$chains != ""} {
37+
set chains_file [open /home/app/.pocket/config/chains.json w]
38+
puts $chains_file $chains
39+
close $chains_file
40+
send_user "CHAINS loaded from env\n"
41+
}
42+
if {$config != ""} {
43+
set config_file [open /home/app/.pocket/config/config.json w]
44+
puts $config_file $config
45+
close $config_file
46+
send_user "CONFIG loaded from env\n"
47+
}
48+
49+
# If key isn't passed in, start the node
50+
if { $env(POCKET_CORE_KEY) eq "" } {
51+
log_user 0
52+
spawn sh -c "$command"
53+
send -- "$env(POCKET_CORE_PASSPHRASE)\n"
54+
log_user 1
55+
} else {
56+
# If key is passed in, load it into the local accounts
57+
log_user 0
58+
spawn pocket accounts import-raw $env(POCKET_CORE_KEY)
59+
sleep 1
60+
send -- "$env(POCKET_CORE_PASSPHRASE)\n"
61+
expect eof
62+
spawn sh -c "pocket accounts set-validator `pocket accounts list | cut -d' ' -f2- `"
63+
sleep 1
64+
send -- "$env(POCKET_CORE_PASSPHRASE)\n"
65+
expect eof
66+
log_user 1
67+
spawn sh -c "$command"
68+
}
69+
70+
expect eof
71+
exit

0 commit comments

Comments
 (0)