From ffb412d128d10c6f3bef62f02f883034c8a64ed7 Mon Sep 17 00:00:00 2001 From: alvicsam Date: Wed, 30 Oct 2024 18:12:25 +0100 Subject: [PATCH] add deploy --- .github/workflows/ci.yml | 15 ++--- .github/workflows/deploy.yml | 123 +++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a38ac37651..e6e594107b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,8 +4,6 @@ on: push: branches: - master - tags: - - v* pull_request: types: [opened, synchronize, reopened, ready_for_review] @@ -39,8 +37,10 @@ jobs: export REF_SLUG=${REF_NAME//\//_} if [[ ${REF_SLUG} == "master" ]] then + VERSION=${REF_SLUG}-${COMMIT_SHA_SHORT} echo "VERSION=${REF_SLUG}-${COMMIT_SHA_SHORT}" >> $GITHUB_OUTPUT else + VERSION=${REF_SLUG} echo "VERSION=${REF_SLUG}" >> $GITHUB_OUTPUT fi echo "set VERSION=${VERSION}" @@ -212,7 +212,7 @@ jobs: mv -v ./ci.Dockerfile ./artifacts/ - name: upload artifacts - uses: actions/upload-artifact@v3 #b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 + uses: actions/upload-artifact@v3 with: name: build path: ./artifacts @@ -226,7 +226,7 @@ jobs: VERSION: ${{ needs.set-variables.outputs.VERSION }} steps: - name: Download artifacts - uses: actions/download-artifact@v3 #fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + uses: actions/download-artifact@v3 with: name: build - name: Make scripts executable @@ -239,13 +239,6 @@ jobs: context: . file: ./ci.Dockerfile push: false - # build-args: tags: | docker.io/paritytech/substrate-relay:${{ env.VERSION }} docker.io/paritytech/bridges-common-relay:${{ env.VERSION }} - - #build image substrate-relay - #build image bridges-common-relay - #build and push image substrate-relay - #build and push image bridges-common-relay - #deploy argocd diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000000..5eec57aa77 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,123 @@ +name: Deploy + +on: + push: + tags: + - v* + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +# common variable is defined in the workflow +# repo env variable doesn't work for PR from forks +env: + CI_IMAGE: "paritytech/ci-unified:bullseye-1.81.0-2024-09-11-v202409111034" + +jobs: + set-variables: + # This workaround sets the container image for each job using 'set-variables' job output. + # env variables don't work for PR from forks, so we need to use outputs. + runs-on: ubuntu-latest + outputs: + CI_IMAGE: ${{ steps.set_image.outputs.CI_IMAGE }} + VERSION: ${{ steps.version.outputs.VERSION }} + steps: + - name: Set image + id: set_image + run: echo "CI_IMAGE=${{ env.CI_IMAGE }}" >> $GITHUB_OUTPUT + - name: Define version + id: version + run: | + export COMMIT_SHA=${{ github.sha }} + export COMMIT_SHA_SHORT=${COMMIT_SHA:0:8} + export REF_NAME=${{ github.ref_name }} + export REF_SLUG=${REF_NAME//\//_} + if [[ ${REF_SLUG} == "master" ]] + then + VERSION=${REF_SLUG}-${COMMIT_SHA_SHORT} + echo "VERSION=${REF_SLUG}-${COMMIT_SHA_SHORT}" >> $GITHUB_OUTPUT + else + VERSION=${REF_SLUG} + echo "VERSION=${REF_SLUG}" >> $GITHUB_OUTPUT + fi + echo "set VERSION=${VERSION}" + + build: + name: Build + runs-on: parity-large + needs: [set-variables] + container: + image: ${{ needs.set-variables.outputs.CI_IMAGE }} + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Build and pack artifact + run: | + cargo fetch + CARGO_NET_OFFLINE=true time cargo build --release --workspace + mkdir -p ./artifacts + strip ./target/release/substrate-relay + mv -v ./target/release/substrate-relay ./artifacts/ + mv -v ./deployments/local-scripts/bridge-entrypoint.sh ./artifacts/ + mv -v ./ci.Dockerfile ./artifacts/ + + - name: upload artifacts + uses: actions/upload-artifact@v3 + with: + name: build + path: ./artifacts + retention-days: 2 + + build_push_docker: + name: Build docker image + runs-on: ubuntu-latest + needs: [set-variables, build] + env: + VERSION: ${{ needs.set-variables.outputs.VERSION }} + steps: + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: build + - name: Make scripts executable + run: | + chmod +x bridge-entrypoint.sh + chmod +x substrate-relay + - name: Build Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./ci.Dockerfile + push: true + tags: | + docker.io/paritytech/substrate-relay:${{ env.VERSION }} + docker.io/paritytech/bridges-common-relay:${{ env.VERSION }} + + deploy-westend: + name: Deploy Westend + runs-on: ubuntu-latest + environment: parity-testnet + needs: [set-variables, build_push_docker] + env: + VERSION: ${{ needs.set-variables.outputs.VERSION }} + ARGOCD_SERVER: "westend-argocd.teleport.parity.io" + steps: + - name: Deploy to ArgoCD + uses: paritytech/argocd-deployment-action@main + with: + environment: "parity-testnet" + tag: "${{ env.VERSION }}" + app_name: "bridges-common-relay" + app_packages: "headers-a,headers-b,parachains-a,parachains-b,messages-a,messages-b" + argocd_server: ${{ env.ARGOCD_SERVER }} + teleport_token: ${{ env.APP }} + teleport_app_name: "argocd-testnet" + argocd_auth_token: ${{ secrets.ARGOCD_AUTH_TOKEN }}