Skip to content

Commit

Permalink
ci(satp-hermes): add docker image deployment actions
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelAPB committed Feb 18, 2025
1 parent acf7ad7 commit 6ead00a
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 123 deletions.
64 changes: 0 additions & 64 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1759,71 +1759,7 @@ jobs:
with:
name: coverage-reports-35
path: ./code-coverage-ts/**/
cactus-plugin-satp-hermes:
continue-on-error: false
env:
FULL_BUILD_DISABLED: true
JEST_TEST_PATTERN: packages/cactus-plugin-satp-hermes/src/test/typescript/(unit|integration|benchmark)/.*/*.test.ts
JEST_TEST_RUNNER_DISABLED: false
TAPE_TEST_RUNNER_DISABLED: true
needs: build-dev
runs-on: ubuntu-22.04
steps:
- name: Use Node.js ${{ env.NODEJS_VERSION }}
uses: actions/setup-node@v4.0.2
with:
node-version: ${{ env.NODEJS_VERSION }}
- uses: actions/checkout@v4.1.1
- id: yarn-cache-dir-path
name: Get yarn cache directory path
run: echo "dir=$(yarn cache dir)" >> "$GITHUB_OUTPUT"
- id: yarn-cache
name: Restore Yarn Cache
uses: actions/cache@v4.0.1
with:
key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
path: ./.yarn/
restore-keys: |
${{ runner.os }}-yarn-
- run: ./tools/ci.sh
cp-bungee-hermes:
continue-on-error: false
env:
# Otherwise it fails with: You are running out of disk space.
# The runner will stop working when the machine runs out of disk space.
# Free space left: 26 MB
FREE_UP_GITHUB_RUNNER_DISK_SPACE_DISABLED: false
FULL_BUILD_DISABLED: true
JEST_TEST_PATTERN: packages/cactus-plugin-satp-hermes/src/test/typescript/(unit|integration|benchmark)/.*/*.test.ts
JEST_TEST_RUNNER_DISABLED: false
JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/cp-bungee-hermes
JEST_TEST_CODE_COVERAGE_ENABLED: true
TAPE_TEST_RUNNER_DISABLED: true
needs: build-dev
runs-on: ubuntu-22.04
steps:
- name: Use Node.js ${{ env.NODEJS_VERSION }}
uses: actions/setup-node@v4.0.3
with:
node-version: ${{ env.NODEJS_VERSION }}
- uses: actions/checkout@v4.1.7

- id: yarn-cache
name: Restore Yarn Cache
uses: actions/cache@v4.0.2
with:
key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
path: ./.yarn/
restore-keys: |
${{ runner.os }}-yarn-
- run: ./tools/ci.sh
if: ${{ env.RUN_CODE_COVERAGE == 'true' }}
- name: Upload coverage reports as artifacts
uses: actions/upload-artifact@v4.3.3
with:
name: coverage-reports-36
path: ./code-coverage-ts/**/
cactus-plugin-bungee-hermes:
continue-on-error: false
env:
FULL_BUILD_DISABLED: true
Expand Down
127 changes: 127 additions & 0 deletions .github/workflows/satp-hermes-gateway.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: SATP CI - tests and docker deployments
on:
pull_request:
branches: [main, dev]
push:
branches: [main, dev]

jobs:
run-satp-tests:
continue-on-error: false
env:
FULL_BUILD_DISABLED: true
JEST_TEST_PATTERN: packages/cactus-plugin-satp-hermes/src/test/typescript/(unit|integration|benchmark)/.*/*.test.ts
JEST_TEST_RUNNER_DISABLED: false
TAPE_TEST_RUNNER_DISABLED: true
needs: build-dev
runs-on: ubuntu-22.04
steps:
- name: Use Node.js ${{ env.NODEJS_VERSION }}
uses: actions/setup-node@v4.0.2
with:
node-version: ${{ env.NODEJS_VERSION }}
- uses: actions/checkout@v4.1.1
- id: yarn-cache-dir-path
name: Get yarn cache directory path
run: echo "dir=$(yarn cache dir)" >> "$GITHUB_OUTPUT"
- id: yarn-cache
name: Restore Yarn Cache
uses: actions/cache@v4.0.1
with:
key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
path: ./.yarn/
restore-keys: |
${{ runner.os }}-yarn-
- run: ./tools/ci.sh

set-docker-tags:
runs-on: ubuntu-22.04
needs: run-satp-tests
if: github.event_name == 'push'
outputs:
tag_suffix: ${{ steps.set_tags.outputs.tag_suffix }}
tag_version: ${{ steps.set_tags.outputs.tag_version }}
dockerhub_image: ${{ steps.set_tags.outputs.dockerhub_image }}
ghcr_image: ${{ steps.set_tags.outputs.ghcr_image }}
steps:
- uses: actions/checkout@v4.1.7
- name: Set image tags
id: set_tags
run: |
TAG_SUFFIX=$(if [ "${{ github.ref }}" = "refs/heads/main" ]; then echo "prod"; else echo "dev"; fi)
TAG_VERSION="$(date -u +"%Y-%m-%dT%H-%M-%S")-${TAG_SUFFIX}-$(git rev-parse --short HEAD)"
DOCKERHUB_IMAGE="hyperledger/satp-hermes-gateway"
GHCR_IMAGE="ghcr.io/hyperledger-cacti/satp-hermes-gateway"
echo "tag_suffix=${TAG_SUFFIX}" >> $GITHUB_OUTPUT
echo "tag_version=${TAG_VERSION}" >> $GITHUB_OUTPUT
echo "dockerhub_image=${DOCKERHUB_IMAGE}" >> $GITHUB_OUTPUT
echo "ghcr_image=${GHCR_IMAGE}" >> $GITHUB_OUTPUT
build-and-push-dockerhub:
runs-on: ubuntu-22.04
needs: set-docker-tags
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4.1.7
- name: Configure and build bundle
run: |
yarn configure
yarn lerna run build:bundle --scope=@hyperledger/cactus-plugin-satp-hermes
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PAT }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./packages/cactus-plugin-satp-hermes/
file: ./packages/cactus-plugin-satp-hermes/satp-hermes-gateway.Dockerfile
push: true
labels: |
org.opencontainers.image.source=https://github.com/hyperledger/cacti
org.opencontainers.image.description=SATP Hermes Gateway
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.vendor=Hyperledger
org.opencontainers.image.version=${{ needs.set-docker-tags.outputs.tag_version }}
org.opencontainers.image.visibility=public
tags: |
${{ needs.set-docker-tags.outputs.dockerhub_image }}:${{ needs.set-docker-tags.outputs.tag_version }}
${{ needs.set-docker-tags.outputs.dockerhub_image }}:latest
build-and-push-ghcr:
runs-on: ubuntu-22.04
needs: set-docker-tags
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4.1.7
- name: Configure and build bundle
run: |
yarn configure
yarn lerna run build:bundle --scope=@hyperledger/cactus-plugin-satp-hermes
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./packages/cactus-plugin-satp-hermes/
file: ./packages/cactus-plugin-satp-hermes/satp-hermes-gateway.Dockerfile
push: true
labels: |
org.opencontainers.image.source=https://github.com/hyperledger/cacti
org.opencontainers.image.description=SATP Hermes Gateway
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.vendor=Hyperledger
org.opencontainers.image.version=${{ needs.set-docker-tags.outputs.tag_version }}
org.opencontainers.image.visibility=public
tags: |
${{ needs.set-docker-tags.outputs.ghcr_image }}:${{ needs.set-docker-tags.outputs.tag_version }}
${{ needs.set-docker-tags.outputs.ghcr_image }}:latest
14 changes: 14 additions & 0 deletions packages/cactus-plugin-satp-hermes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ docker compose \
--build
```

To push the current version to the official repo, run (tested in MacOS):
```sh
IMAGE_NAME=ghcr.io/hyperledger-cacti/satp-hermes-gateway
DEV_TAG="$(date -u +"%Y-%m-%dT%H-%M-%S")-dev-$(git rev-parse --short HEAD)"

echo "Building Docker image with name: $IMAGE_NAME:$DEV_TAG"

docker build \
--file ./packages/cactus-plugin-satp-hermes/satp-hermes-gateway.Dockerfile \
./packages/cactus-plugin-satp-hermes/ \
--tag $IMAGE_NAME:$DEV_TAG \
--tag $IMAGE_NAME:latest
```

> The `--build` flag is going to save you 99% of the time from docker compose caching your image builds against your will or knowledge during development.
## Contributing
Expand Down
Loading

0 comments on commit 6ead00a

Please sign in to comment.