Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: docker release workflow #257

Merged
merged 31 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f467791
docker release workflow
mrq1911 May 15, 2021
084cc0b
params fix
mrq1911 May 15, 2021
3a0cb5b
tag by branch
mrq1911 May 15, 2021
3220211
added arm build
mrq1911 May 15, 2021
8fb9eeb
fixed builder deps
mrq1911 May 15, 2021
be90142
extracted branch name
mrq1911 May 15, 2021
6b8cb21
run in dedicated runner
mrq1911 May 15, 2021
1c21a9a
fixed workflow
mrq1911 May 15, 2021
b60bf45
runner not found?
mrq1911 May 15, 2021
c1309a3
sleep fixed
mrq1911 May 15, 2021
4e16494
run on special runner (temporary)
mrq1911 May 15, 2021
a8d3d19
they took our jobs
mrq1911 May 15, 2021
2eb8873
push fix, only one platform for now
mrq1911 May 16, 2021
01cf7ff
ghcr
mrq1911 May 16, 2021
3cd5c88
dockerfile linked to repo
mrq1911 May 16, 2021
b87dd60
auth?
mrq1911 May 16, 2021
c025487
manual login
mrq1911 May 16, 2021
4ecd591
registry ... duh
mrq1911 May 17, 2021
27178a0
arm crosscompile
mrq1911 May 17, 2021
323f59e
build on aws runner
mrq1911 May 17, 2021
bcb03c2
fixed docker ami
mrq1911 May 17, 2021
9376adc
try to enable experimental cli
mrq1911 May 17, 2021
aad26fc
ami with fixed docker
mrq1911 May 17, 2021
a449fa5
mby this ami
mrq1911 May 17, 2021
7b93249
Merge branch 'master' into docker-release
mrq1911 May 18, 2021
be4ba1e
docker swarm stackfile
mrq1911 May 18, 2021
22f42e2
describe version correctly
mrq1911 May 18, 2021
3c9941d
use already pulled repo
mrq1911 May 19, 2021
eedadc3
Merge branch 'master' into docker-release
mrq1911 May 19, 2021
5b208f3
Merge branch 'master' into docker-release
jak-pan May 25, 2021
f04ec3b
Merge branch 'master' into docker-release
mrq1911 May 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
117 changes: 117 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: docker release

on:
push:
branches:
- master
- stable
- docker-release
tags:

jobs:
pop-runner-instance:
name: create and setup infrastructure for branch
runs-on: ubuntu-latest
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
EC2_SECRET: ${{ secrets.EC2_PWD }}
S3_BACKEND_KEY_NAME: tf-state-${{ github.sha }}-docker
steps:
- name: checkout code
uses: actions/[email protected]
- name: setup node
uses: actions/setup-node@v2
with:
node-version: '14'
- uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.12.25
- name: rewrite tf state key
working-directory: ./infrastructure
run: sed -i 's/BRANCH_ACTOR_KEY/${{ env.S3_BACKEND_KEY_NAME }}/g' infra.tf
- name: Terraform Init
working-directory: ./infrastructure
run: terraform init
- name: Terraform plan
working-directory: ./infrastructure
run: terraform plan -var="ec2_pwd=$EC2_SECRET" -var="branch_name=${{ github.sha }}-docker"
- name: Terraform apply
working-directory: ./infrastructure
run: terraform apply -var="ec2_pwd=$EC2_SECRET" -var="branch_name=${{ github.sha }}-docker" -auto-approve
- name: Sleep for 20 seconds
uses: jakejarvis/wait-action@master
with:
time: '20s'

docker-build:
runs-on: ${{ format('{0}-docker', github.sha) }}
needs: pop-runner-instance
env:
DOCKER_CLI_EXPERIMENTAL: enabled
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Describe version
run: git describe --tags --abbrev=0
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.PKG_USER }}
jak-pan marked this conversation as resolved.
Show resolved Hide resolved
password: ${{ secrets.PKG_PWD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ghcr.io/galacticcouncil/hydra-dx:${{ steps.extract_branch.outputs.branch }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

destroy-runner-instance:
name: destroy infra
runs-on: ubuntu-latest
needs: docker-build
if: always()
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
EC2_SECRET: ${{ secrets.EC2_PWD }}
S3_BACKEND_KEY_NAME: tf-state-${{ github.sha }}-docker
steps:
- name: checkout code
uses: actions/[email protected]
- name: setup node
uses: actions/setup-node@v2
with:
node-version: '14'
- uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.12.25
continue-on-error: false
- name: rewrite tf state key
working-directory: ./infrastructure
run: sed -i 's/BRANCH_ACTOR_KEY/${{ env.S3_BACKEND_KEY_NAME }}/g' infra.tf
- name: Terraform Init
working-directory: ./infrastructure
run: terraform init
- name: Terraform apply
working-directory: ./infrastructure
run: terraform destroy -var="ec2_pwd=$EC2_SECRET" -var="branch_name=${{ github.sha }}-docker" -auto-approve
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM rust:latest as builder
mrq1911 marked this conversation as resolved.
Show resolved Hide resolved

RUN apt update && apt install -y git clang curl libssl-dev llvm libudev-dev

WORKDIR /build

COPY . /build

RUN cargo build --release

FROM debian:buster-slim
LABEL org.opencontainers.image.source = "https://github.com/galacticcouncil/HydraDX-node"
COPY --from=builder /build/target/release/hydra-dx /usr/local/bin

RUN useradd -m -u 1000 -U -s /bin/sh -d /hydra hydra && \
mkdir -p /hydra/.local/share && \
mkdir /data && \
chown -R hydra:hydra /data && \
ln -s /data /hydra/.local/share/hydra-dx && \
rm -rf /usr/bin /usr/sbin

USER hydra
EXPOSE 30333 9933 9944
VOLUME ["/data"]

CMD ["/usr/local/bin/hydra-dx","--chain","lerna"]
mrq1911 marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions infrastructure/infra.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ variable "ec2_pwd" {


resource "aws_instance" "runner-aws" {
ami = "ami-04f71779ae623a544"
ami = "ami-058872f0d7afad104"
instance_type = "c5ad.4xlarge"
subnet_id = "subnet-0ba99ac0d4aea3dc6"
key_name = "aws-ec2-key"
Expand All @@ -52,4 +52,4 @@ resource "aws_instance" "runner-aws" {
"tmux new -d 'bash run_conf.sh ${var.branch_name}'"
]
}
}
}
17 changes: 17 additions & 0 deletions stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.3'
services:
node:
image: ghcr.io/galacticcouncil/hydra-dx:docker-release
command: hydra-dx --chain lerna
volumes:
- data:/data
networks:
- default
logging:
driver: json-file
networks:
default:
driver: overlay
volumes:
data:
driver: local