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

cicd: rework workflows #191

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
113 changes: 83 additions & 30 deletions .github/workflows/build_tzsafe.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
name: Automatic build and push
#builds docker img and creates tags for the versions

on:
push:
branches:
- main
- release
- dev
- ghostnet
- mainnet
pull_request:
branches:
- main
- release
- dev
- ghostnet
- mainnet
workflow_dispatch:
inputs:
manual_tagging_version:
description: "Create version at current head commit on mainnet branch, specify tag/version bellow (e.g., v1.2.3)"
required: true
default: ""

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -19,6 +28,7 @@ jobs:
name: "Docker build"
runs-on: ubuntu-latest
steps:
# setting up the environment
- name: Checkout
uses: actions/checkout@v3

Expand All @@ -31,58 +41,101 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v6.1
if: ${{ github.event_name != 'pull_request' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
release_branches: release
pre_release_branches: main
default_bump: minor
default_prerelease_bump: prepatch
append_to_pre_release_tag: rc

- name: Testing
if: ${{ github.event_name == 'pull_request' && github.ref == 'refs/heads/main' }}
# Testing
- name: Testing code
if: ${{ github.ref == 'refs/heads/ghostnet' }}
uses: actions/setup-node@v4
with:
node-version: "18.x"
run: |
npm ci
npm t

- name: Build
if: ${{ startsWith(github.ref,'refs/heads/') || github.event_name == 'pull_request' }}
# Build testing
- name: Testing docker build
if: ${{ github.event_name == 'pull_request' && github.ref == 'refs/heads/dev' }}
uses: docker/build-push-action@v4
with:
file: ./Dockerfile
push: false
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: ENV=prod
build-args: |
PUBLIC_RPC_URL=https://ghostnet.tezos.marigold.dev/
PUBLIC_API_URL=https://api.ghostnet.tzkt.io
PUBLIC_NETWORK_TYPE=ghostnet
# tagging
- name: Set tagging variables
if: ${{ github.ref != 'refs/heads/dev' }}
id: vars
run: |
echo "date=$(date +%Y-%m-%dT%H-%M-%S)" >> "${GITHUB_OUTPUT}"
echo "sha_short=$(git rev-parse --short HEAD)" >> "${GITHUB_OUTPUT}"

- name: Build and push staging version
if: ${{ ! github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
- name: Fetch tags
if: ${{ github.ref != 'refs/heads/dev' }}
run: |
git fetch --prune --unshallow

- name: Determine Tag Version
if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/mainnet' }}
id: tag_version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.manual_tagging_version }}" ]]; then
NEW_TAG="${{ github.event.inputs.manual_tagging_version }}"
echo "Manual version override: $NEW_TAG"
else
# Determine new stable version
TAG=$(git tag -l | grep -v 'rc' | sort -V | tail -n1)
MAJOR=$(echo $TAG | sed -r 's/v([0-9]+)\.([0-9]+)\.([0-9]+)/\1/')
MINOR=$(echo $TAG | sed -r 's/v([0-9]+)\.([0-9]+)\.([0-9]+)/\2/')
if [ "$MINOR" -eq 99 ]; then
NEW_MAJOR=$((MAJOR + 1))
NEW_MINOR=0
else
NEW_MAJOR=$MAJOR
NEW_MINOR=$((MINOR + 1))
fi
NEW_TAG="v${NEW_MAJOR}.${NEW_MINOR}.0"
echo "Previous Tag: $TAG"
echo "Automatically calculated new version: $NEW_TAG"
fi
echo "new_version=$NEW_TAG" >> "${GITHUB_OUTPUT}"
echo "Tag that will be used: $NEW_TAG"

- name: Create Git tag
if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/mainnet' }}
run: git tag ${{ steps.tag_version.outputs.new_version}} && git push origin ${{ steps.tag_version.outputs.new_version}}

# building and pushing docker images
- name: Build and push staging docker image
if: ${{ github.ref == 'refs/heads/ghostnet' }}
uses: docker/build-push-action@v4
with:
file: ./Dockerfile
push: true
tags: |
ghcr.io/marigold-dev/tzsafe:${{ steps.tag_version.outputs.new_version}}
ghcr.io/marigold-dev/tzsafe:staging
ghcr.io/marigold-dev/tzsafe:${{ steps.vars.outputs.date }}-${{ steps.vars.outputs.sha_short }}-staging
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: ENV=dev
- name: Build and push release version
if: ${{ github.event_name == 'pull_request' && github.ref == 'refs/heads/release' }}
build-args: |
PUBLIC_RPC_URL=https://ghostnet.tezos.marigold.dev/
PUBLIC_API_URL=https://api.ghostnet.tzkt.io
PUBLIC_NETWORK_TYPE=ghostnet

- name: Build and push release docker image
if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/mainnet' }}
uses: docker/build-push-action@v4
with:
file: ./Dockerfile
push: true
tags: |
ghcr.io/marigold-dev/tzsafe:stable
ghcr.io/marigold-dev/tzsafe:${{ steps.tag_version.outputs.new_version}}-release
ghcr.io/marigold-dev/tzsafe:${{ steps.vars.outputs.date }}-${{ steps.vars.outputs.sha_short }}-${{ steps.tag_version.outputs.new_version}}-release
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: ENV=prod
build-args: |
PUBLIC_RPC_URL=https://mainnet.tezos.marigold.dev/
PUBLIC_API_URL=https://api.tzkt.io
PUBLIC_NETWORK_TYPE=mainnet
7 changes: 4 additions & 3 deletions .github/workflows/deploy_ghpages.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: Automatic deploy to GHPages
#deploys the mainnet version to GHPages

on:
push:
branches:
- release
- mainnet
pull_request:
branches:
- release
- mainnet

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
Expand Down Expand Up @@ -59,6 +60,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
if: ${{ github.ref == 'refs/heads/release' }}
if: ${{ github.ref == 'refs/heads/mainnet' }}
id: deployment
uses: actions/deploy-pages@v4
15 changes: 7 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ COPY --from=deps /app/node_modules ./node_modules

COPY . .

RUN \
if [ "$ENV" = "prod" ]; then \
echo -en "NEXT_PUBLIC_RPC_URL=https://mainnet.tezos.marigold.dev/\nNEXT_PUBLIC_API_URL=https://api.tzkt.io\nNEXT_PUBLIC_NETWORK_TYPE=mainnet" > .env.local; \
else \
echo -en "NEXT_PUBLIC_RPC_URL=https://ghostnet.tezos.marigold.dev/\nNEXT_PUBLIC_API_URL=https://api.ghostnet.tzkt.io\nNEXT_PUBLIC_NETWORK_TYPE=ghostnet" > .env.local; \
fi
ARG PUBLIC_RPC_URL="https://rpc.tzkt.io/mainnet/"
ARG PUBLIC_API_URL="https://api.tzkt.io"
ARG PUBLIC_NETWORK_TYPE="mainnet"

RUN echo -en "NEXT_PUBLIC_RPC_URL=$PUBLIC_RPC_URL/\nNEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL\NEXT_PUBLIC_NETWORK_TYPE=$PUBLIC_NETWORK_TYPE" > .env.local;

RUN npm run build

EXPOSE 80
FROM nginx:alpine
COPY --from=builder /app/out/ /usr/share/nginx/html

CMD ["npm", "start"]
EXPOSE 80

28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,38 @@ Finally you can develop with:
npm run dev
```

### How to build the code
### How to run

Once you updated the code, you can build it with:
There are two ways to run TzSafe, with or without docker.

#### Docker

```bash
npm run build
docker build -t tzsafe .
docker run -p 8080:80 tzsafe
```

And serve the build with:
When building the application you can specify which node and which network you want to use:

```bash
npm start
docker build --build-arg="PUBLIC_RPC_URL=https://mainnet.tezos.marigold.dev" -t tzsafe .
```

You can override:

- PUBLIC_RPC_URL: the URL of the node you want to use (default: https://rpc.tzkt.io/mainnet/)
- PUBLIC_API_URL: the URL of a tzkt instance (default: https://api.tzkt.io)
- PUBLIC_NETWORK_TYPE: the type of the network (default: mainnet)

### With NPM

```
npm i
npm run start:mainnet
```

You can override the variable by editing the file `/config/.env.mainnet`

## Sandbox

Sandbox enables us to locally run Tezos-node and Tzkt. There are two modes: stateful and stateless. In stateful mode, the data of Tezos-node and the database of Tzkt are preserved when docker compose stops, while in stateless mode, both start from the genesis block.
Expand Down
3 changes: 3 additions & 0 deletions config/.env.mainnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NEXT_PUBLIC_RPC_URL=https://mainnet.tezos.marigold.dev/
NEXT_PUBLIC_API_URL=https://api.tzkt.io
NEXT_PUBLIC_NETWORK_TYPE=mainnet
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"sandbox": "env-cmd -f ./config/.env.sandbox next dev --port 4000",
"build": "next build",
"build:dev": "env-cmd -f ./config/.env.dev next build",
"start": "next start --port 80",
"build:mainnet": "env-cmd -f ./config/.env.mainnet next build",
"start:mainnet": "env-cmd -f ./config/.env.mainnet next dev",
"lint": "next lint",
"format": "prettier --write pages/ components/ context/ types/ versioned/ utils/ test/",
"prepare": "husky install",
Expand Down
Loading