Migrate S3 - preprod #20
Workflow file for this run
This file contains 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
--- | |
name: Alfresco s3 Migration | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: Environment to copy data to | |
required: true | |
type: choice | |
options: | |
- poc | |
- dev | |
- test | |
- stage | |
- preprod | |
- prod | |
permissions: | |
contents: read | |
run-name: Migrate S3 - ${{ github.event.inputs.environment }} | |
jobs: | |
migrate-s3: | |
name: Migrate S3 | |
runs-on: ubuntu-22.04 | |
environment: | |
name: ${{ github.event.inputs.environment }} | |
steps: | |
- uses: actions/[email protected] | |
- name: Install kubectl | |
uses: azure/[email protected] | |
with: | |
version: 'v1.26.0' # default is latest stable | |
id: kubectl_install | |
- uses: azure/[email protected] | |
with: | |
version: 'v3.15.3' # default is latest (stable) | |
id: install | |
- name: Configure kubectl | |
run: | | |
echo "${{ secrets.KUBE_CERT }}" > ca.crt | |
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER} | |
kubectl config set-credentials deploy-user --token=${{ secrets.KUBE_TOKEN }} | |
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE} | |
kubectl config use-context ${KUBE_CLUSTER} | |
env: | |
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }} | |
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }} | |
- name: Uninstall S3 Refresh chart | |
run: helm uninstall migrate-s3 --ignore-not-found | |
- name: S3 migration | |
working-directory: jobs/migrate-s3 | |
run: | | |
set -xeo pipefail | |
SERVICE_POD_DEPLOYMENT=$(kubectl get deployment -l app=service-pod -o jsonpath="{.items[0].metadata.name}") | |
SERVICE_POD_NAME=$(kubectl get pod -l app=$SERVICE_POD_DEPLOYMENT -o jsonpath="{.items[0].metadata.name}") | |
SRC_BUCKET="${{ vars.MIGRATION_SRC_BUCKET }}" | |
prefixes=$(kubectl exec $SERVICE_POD_NAME -- aws s3api list-objects-v2 --bucket $SRC_BUCKET --delimiter '/' --query 'CommonPrefixes[*].Prefix' --output text) | |
# remove all spaces and put one comma between prefixes | |
cleaned_prefixes=$(echo $prefixes | tr -s '[:space:]' ',' | sed 's/[,/]*$//') | |
DIRS="" | |
IFS=',' | |
for prefix in $cleaned_prefixes; do | |
DIR=$(kubectl exec $SERVICE_POD_NAME -- aws s3api list-objects-v2 --bucket $SRC_BUCKET --prefix "$prefix" --delimiter '/' --query 'CommonPrefixes[*].Prefix' --output text) | |
if [ -n "$DIR" ]; then | |
DIR=$(echo $DIR | tr -s '[:space:]' ',' | sed 's/[,/]*$//') | |
DIRS="${DIRS}${DIR}," | |
fi | |
done | |
DIRS=${DIRS%,} | |
echo "DIRS: $DIRS" | |
helm install migrate-s3 . \ | |
--set environment=${{ github.event.inputs.environment }} \ | |
--set srcBucket=$SRC_BUCKET \ | |
--set "directories={${DIRS}}" | |
kubectl wait jobs -l name-prefix=migrate-s3 --for=condition=complete --timeout 10h | |
- name: Uninstall S3 Refresh chart | |
run: helm uninstall migrate-s3 --ignore-not-found |