-
Notifications
You must be signed in to change notification settings - Fork 28
Add workflows for video2commons deployment #303
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
Open
Amdrel
wants to merge
3
commits into
master
Choose a base branch
from
continuous-deployment
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+360
−33
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| name: Deploy Encoders (CloudVPS) | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| # Uncomment to allow the workflow to run automatically when changes are | ||
| # merged into master (only for files that affect this deployment). | ||
| # | ||
| # push: | ||
| # branches: [master] | ||
| # paths: | ||
| # - 'puppet/**' | ||
| # - 'pyproject.toml' | ||
| # - 'utils/deploy-cloudvps-encoders.sh' | ||
| # - 'uv.lock' | ||
| # - 'video2commons/backend/**' | ||
| # - 'video2commons/config.py' | ||
| # - 'video2commons/exceptions.py' | ||
| # - 'video2commons/shared/**' | ||
|
|
||
| jobs: | ||
| deploy-cloudvps-encoders: | ||
| name: Deploy Encoders (CloudVPS) | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup SSH | ||
| run: | | ||
| mkdir -p ~/.ssh | ||
| echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519 | ||
| chmod 600 ~/.ssh/id_ed25519 | ||
| cat >> ~/.ssh/config << 'EOF' | ||
| Host * | ||
| IdentityFile ~/.ssh/id_ed25519 | ||
| IdentitiesOnly yes | ||
| StrictHostKeyChecking no | ||
|
|
||
| Host *.wikimedia.cloud | ||
| ProxyJump login.toolforge.org:22 | ||
| EOF | ||
| chmod 600 ~/.ssh/config | ||
| mkdir -p ~/.ssh/sockets | ||
|
|
||
| - name: Deploy | ||
| run: ./utils/deploy-cloudvps-encoders.sh | ||
| env: | ||
| V2C_USERNAME: ${{ secrets.V2C_USERNAME }} | ||
| V2C_REDIS_PW: ${{ secrets.V2C_REDIS_PW }} | ||
| V2C_CONSUMER_SECRET: ${{ secrets.V2C_CONSUMER_SECRET }} | ||
| V2C_CONSUMER_KEY: ${{ secrets.V2C_CONSUMER_KEY }} | ||
47 changes: 47 additions & 0 deletions
47
.github/workflows/deploy-toolforge-video2commons-socketio.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| name: Deploy Socket.IO (Toolforge) | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| # Uncomment to allow the workflow to run automatically when changes are | ||
| # merged into master (only for files that affect this deployment). | ||
| # | ||
| # push: | ||
| # branches: [master] | ||
| # paths: | ||
| # - 'package-lock.json' | ||
| # - 'package.json' | ||
| # - 'utils/deploy-toolforge-socketio.sh' | ||
| # - 'video2commons-socketio/**' | ||
|
|
||
| jobs: | ||
| deploy-toolforge-video2commons-socketio: | ||
| name: Deploy Socket.IO (Toolforge) | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup SSH | ||
| run: | | ||
| mkdir -p ~/.ssh | ||
| echo '${{ secrets.SSH_PRIVATE_KEY }}' > ~/.ssh/id_ed25519 | ||
| chmod 600 ~/.ssh/id_ed25519 | ||
| cat >> ~/.ssh/config << 'EOF' | ||
| Host * | ||
| IdentityFile ~/.ssh/id_ed25519 | ||
| IdentitiesOnly yes | ||
| StrictHostKeyChecking no | ||
| ControlMaster auto | ||
| ControlPath ~/.ssh/sockets/%r@%h-%p | ||
| ControlPersist 60 | ||
| EOF | ||
| chmod 600 ~/.ssh/config | ||
| mkdir -p ~/.ssh/sockets | ||
|
|
||
| - name: Deploy | ||
| run: ./utils/deploy-toolforge-socketio.sh | ||
| env: | ||
| V2C_SERVICE_NAME: video2commons-socketio | ||
| V2C_USERNAME: ${{ secrets.V2C_USERNAME }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| name: Deploy Test Frontend (Toolforge) | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| push: | ||
| branches: [master] | ||
| paths: | ||
| - 'Gulpfile.mjs' | ||
| - 'package-lock.json' | ||
| - 'package.json' | ||
| - 'pyproject.toml' | ||
| - 'utils/deploy-toolforge-frontend.sh' | ||
| - 'uv.lock' | ||
| - 'video2commons/config.py' | ||
| - 'video2commons/exceptions.py' | ||
| - 'video2commons/frontend/**' | ||
| - 'video2commons/shared/**' | ||
|
|
||
| jobs: | ||
| deploy-toolforge-video2commons-test: | ||
| name: Deploy Test Frontend (Toolforge) | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version-file: '.nvmrc' | ||
| cache: 'npm' | ||
|
|
||
| - name: Remove broken symlinks | ||
| run: | | ||
| rm -f video2commons/frontend/static/ssu | ||
| rm -f video2commons/frontend/static/uploads | ||
|
|
||
| - name: Build | ||
| run: | | ||
| npm ci | ||
| npx gulp build | ||
|
|
||
| - name: Setup SSH | ||
| run: | | ||
| mkdir -p ~/.ssh | ||
| echo '${{ secrets.SSH_PRIVATE_KEY }}' > ~/.ssh/id_ed25519 | ||
| chmod 600 ~/.ssh/id_ed25519 | ||
| cat >> ~/.ssh/config << 'EOF' | ||
| Host * | ||
| IdentityFile ~/.ssh/id_ed25519 | ||
| IdentitiesOnly yes | ||
| StrictHostKeyChecking no | ||
| ControlMaster auto | ||
| ControlPath ~/.ssh/sockets/%r@%h-%p | ||
| ControlPersist 60 | ||
| EOF | ||
| chmod 600 ~/.ssh/config | ||
| mkdir -p ~/.ssh/sockets | ||
|
|
||
| - name: Deploy | ||
| run: ./utils/deploy-toolforge-frontend.sh | ||
| env: | ||
| V2C_SERVICE_NAME: video2commons-test | ||
| V2C_USERNAME: ${{ secrets.V2C_USERNAME }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| name: Deploy Frontend (Toolforge) | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| # Uncomment to allow the workflow to run automatically when changes are | ||
| # merged into master (only for files that affect this deployment). | ||
| # | ||
| # push: | ||
| # branches: [master] | ||
| # paths: | ||
| # - 'Gulpfile.mjs' | ||
| # - 'package-lock.json' | ||
| # - 'package.json' | ||
| # - 'pyproject.toml' | ||
| # - 'utils/deploy-toolforge-frontend.sh' | ||
| # - 'uv.lock' | ||
| # - 'video2commons/config.py' | ||
| # - 'video2commons/exceptions.py' | ||
| # - 'video2commons/frontend/**' | ||
| # - 'video2commons/shared/**' | ||
|
|
||
| jobs: | ||
| deploy-toolforge-video2commons: | ||
| name: Deploy Frontend (Toolforge) | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version-file: '.nvmrc' | ||
| cache: 'npm' | ||
|
|
||
| - name: Remove broken symlinks | ||
| run: | | ||
| rm -f video2commons/frontend/static/ssu | ||
| rm -f video2commons/frontend/static/uploads | ||
|
|
||
| - name: Build | ||
| run: | | ||
| npm ci | ||
| npx gulp build | ||
|
|
||
| - name: Setup SSH | ||
| run: | | ||
| mkdir -p ~/.ssh | ||
| echo '${{ secrets.SSH_PRIVATE_KEY }}' > ~/.ssh/id_ed25519 | ||
| chmod 600 ~/.ssh/id_ed25519 | ||
| cat >> ~/.ssh/config << 'EOF' | ||
| Host * | ||
| IdentityFile ~/.ssh/id_ed25519 | ||
| IdentitiesOnly yes | ||
| StrictHostKeyChecking no | ||
| ControlMaster auto | ||
| ControlPath ~/.ssh/sockets/%r@%h-%p | ||
| ControlPersist 60 | ||
| EOF | ||
| chmod 600 ~/.ssh/config | ||
| mkdir -p ~/.ssh/sockets | ||
|
|
||
| - name: Deploy | ||
| run: ./utils/deploy-toolforge-frontend.sh | ||
| env: | ||
| V2C_SERVICE_NAME: video2commons | ||
| V2C_USERNAME: ${{ secrets.V2C_USERNAME }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Note: All ssh commands share the same connection for the lifetime of this | ||
| # script if run via the workflows. | ||
| # | ||
| # The follow ssh options are used by the workflow: | ||
| # ControlMaster auto | ||
| # ControlPath ~/.ssh/sockets/%r@%h-%p | ||
| # ControlPersist 60 | ||
|
|
||
| bastion_host=login.toolforge.org | ||
|
|
||
| if [ -z "$V2C_USERNAME" ]; then | ||
| echo "Error: V2C_USERNAME environment variable is not set" >&2 | ||
| exit 1 | ||
| elif [ -z "$V2C_SERVICE_NAME" ]; then | ||
| echo "Error: V2C_SERVICE_NAME environment variable is not set" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| remote_repo_path="/data/project/$V2C_SERVICE_NAME" | ||
| script_dir="$(cd "$(dirname "$0")" && pwd)" | ||
| host_repo_root="$script_dir/.." | ||
| tmp_dir="/tmp/v2c-deploy-$V2C_SERVICE_NAME" | ||
|
|
||
| echo "Updating video2commons frontend..." | ||
|
|
||
| # Pull in the latest changes from the repository currently in master. | ||
| ssh "$V2C_USERNAME@$bastion_host" "become $V2C_SERVICE_NAME bash -c 'cd $remote_repo_path && git pull'" | ||
|
|
||
| if [ $? -ne 0 ]; then | ||
| echo "Failed to pull most recent changes for v2c" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Create a temp directory for temporarily storing the minified files. | ||
| ssh "$V2C_USERNAME@$bastion_host" "mkdir -p $tmp_dir" | ||
|
|
||
| if [ $? -ne 0 ]; then | ||
| echo "Failed to create temporary directory at $tmp_dir" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Upload the minified files to the new temp directory. | ||
| scp "$host_repo_root/video2commons/frontend/static/"*.min.js \ | ||
| "$host_repo_root/video2commons/frontend/templates/"*.min.html \ | ||
| "$V2C_USERNAME@$bastion_host:$tmp_dir/" | ||
|
|
||
| if [ $? -ne 0 ]; then | ||
| echo "Failed to copy minified files to remote" >&2 | ||
| ssh "$V2C_USERNAME@$bastion_host" "rm -rf $tmp_dir" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Copy the minified files to destination with correct ownership, then cleanup. | ||
| ssh "$V2C_USERNAME@$bastion_host" "become $V2C_SERVICE_NAME bash -c ' | ||
| cp $tmp_dir/*.min.js $remote_repo_path/video2commons/frontend/static/ | ||
| cp $tmp_dir/*.min.html $remote_repo_path/video2commons/frontend/templates/ | ||
| ' && rm -rf $tmp_dir" | ||
|
|
||
| if [ $? -ne 0 ]; then | ||
| echo "Failed to move minified files to destination" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Restart the webservice so any Python changes are applied. | ||
| ssh "$V2C_USERNAME@$bastion_host" "become $V2C_SERVICE_NAME toolforge webservice python3.11 restart" | ||
|
|
||
| # Cleanup the SSH control socket that we use to keep the connection alive | ||
| # across multiple ssh command executions. | ||
| ssh -O exit "$V2C_USERNAME@$bastion_host" 2>/dev/null || true | ||
|
|
||
| echo "Done" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These secrets don't exist yet, are you able to create them or do you want me to create them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I should be able to with my permissions. I'll let you know if I run into any problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the secrets to the repository-level secrets. I don't have access to the environment-level secrets, which is where I assume
SSH_PRIVATE_KEYis located. Is this fine?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I set
V2C_USERNAMEtoadminv2csince that's what I saw in the membership requests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah strange, I must have missed something, I would prefer to set all secrets in the environment, I'm checking your permissions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've set you to maintainer role, is it enough now to have access to env secrets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't see it. I'm not sure what permission controls the visibility of that section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK now you're admin I can't give you more permissions :D Is it working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seemed to do it. I'll get those updated here shortly 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done