Skip to content

Commit

Permalink
Dockerize the binaries #579
Browse files Browse the repository at this point in the history
  • Loading branch information
mosonyi committed Mar 4, 2022
1 parent e0c246b commit 8428603
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,56 @@ jobs:
with:
name: ${{ matrix.test }}_logs
path: ${{ env.LOG_DIR }}

release:
name: Draft Release
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: [build-test, integration-tests]
outputs:
release_url: ${{ steps.create-release.outputs.html_url }}
asset_upload_url: ${{ steps.create-release.outputs.upload_url }}
steps:
- uses: actions/checkout@v2

- name: Download Integritee Service
uses: actions/download-artifact@v2
with:
name: integritee-worker-${{ github.sha }}
path: integritee-worker-tmp

- name: Download Integritee Client
uses: actions/download-artifact@v2
with:
name: integritee-client-${{ github.sha }}
path: integritee-client-tmp

- name: Move service binaries
run: mv integritee-worker-tmp/integritee-service ./integritee-service-dev

- name: Move service client binaries
run: mv integritee-client-tmp/integritee-cli ./integritee-client

- name: Create required package.json
run: test -f package.json || echo '{}' >package.json

- name: Changelog
uses: scottbrenner/generate-changelog-action@master
id: Changelog

- name: Display structure of downloaded files
run: ls -R
working-directory: .

- name: Release
id: create-release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: |
${{ steps.Changelog.outputs.changelog }}
draft: true
files: |
integritee-client
integritee-service-dev
65 changes: 65 additions & 0 deletions .github/workflows/delete-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Delete-Release

on:
release:
types: [deleted] # should be deleted

jobs:
purge-image:
name: Delete image from ghcr.io
runs-on: ubuntu-latest
strategy:
matrix:
binary: ["integritee-client", "integritee-service-dev"]
steps:
- uses: actions/checkout@v2

- name: Set output
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}

- name: Check output
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
run: |
echo $RELEASE_VERSION
echo ${{ steps.vars.outputs.tag }}
echo ${{github.event.pull_request.number}}
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

# Unfortunately accessing the repo with personal access token is not possible
# Workaround: disable 2FA and user password instead of TOKEN
- name: Delete docker tag
run: |
ORGANIZATION="integritee"
IMAGE="${{ matrix.binary }}"
TAG="${{ steps.vars.outputs.tag }}"
login_data() {
cat <<EOF
{
"username": "${{ secrets.DOCKER_HUB_USERNAME }}",
"password": "${{ secrets.DOCKERHUB_PASSWORD }}"
}
EOF
}
TOKEN=`curl -s -H "Content-Type: application/json" -X POST -d "$(login_data)" "https://hub.docker.com/v2/users/login/" | jq -r .token`
curl "https://hub.docker.com/v2/repositories/${ORGANIZATION}/${IMAGE}/tags/${TAG}/" \
-X DELETE \
-H "Authorization: JWT ${TOKEN}"
- name: Delete tag as well
uses: dev-drprasad/[email protected]
with:
delete_release: false # it is triggered by release deletion
tag_name: ${{ steps.vars.outputs.tag }} # tag name to delete
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56 changes: 56 additions & 0 deletions .github/workflows/publish-docker-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Publish Docker image for new releases

on:
release:
types:
- published

jobs:
main:
name: Push Integritee Node to Dockerhub
runs-on: ubuntu-latest
strategy:
matrix:
binary: ["integritee-service-dev", "integritee-client"]
steps:
- uses: actions/checkout@v2

- name: Download ${{ matrix.binary }} from release
uses: dsaltares/fetch-gh-release-asset@master
with:
version: "tags/${{ github.event.release.tag_name }}"
file: "${{ matrix.binary }}"
target: "integritee-service"
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
build-args: BINARY_FILE=${{ matrix.binary }}

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Dockerhub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
context: .
tags: |
integritee/${{ matrix.binary }}:${{ github.event.release.tag_name }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM integritee/integritee-dev:0.1.9
LABEL maintainer="[email protected]"

# By default we warp the service-dev
ARG BINARY_FILE=integritee-service-dev

RUN echo "Oh dang look at that ${BINARY_FILE}"

COPY ${BINARY_FILE} /usr/local/bin
RUN chmod +x /usr/local/bin/${BINARY_FILE}

# checks
RUN ldd /usr/local/bin/${BINARY_FILE} && \
/usr/local/bin/${BINARY_FILE} --version

ENV entrypoint="/usr/local/bin/${BINARY_FILE}"

ENTRYPOINT ${entrypoint}

0 comments on commit 8428603

Please sign in to comment.