-
Notifications
You must be signed in to change notification settings - Fork 16
/
.gitlab-ci.yml
77 lines (71 loc) · 2.59 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
variables:
GITLAB_ENV: development
workflow:
rules:
- if: $CI_COMMIT_REF_NAME == "main"
variables:
GITLAB_ENV: production
- when: always
stages:
- deploy
- mirror
- github-pull
deploy-job:
stage: deploy
environment: $GITLAB_ENV
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
script:
- aws s3 sync --delete --acl public-read --exclude "*" --include "*/assets/*" --exclude "*/.gitkeep" recipes s3://${HPCDK_S3_BUCKET}/${CI_COMMIT_BRANCH}/recipes/
mirror-to-github:
stage: mirror
image: alpine:latest
rules:
- if: $CI_COMMIT_BRANCH == "main"
before_script:
- apk add --no-cache git openssh-client
- eval $(ssh-agent -s)
- echo "${GITHUB_SSH_PRIVATE_KEY}" | tr -d '\r' | sed -e 's/^[ \t]*//' | sed -e 's/[ \t]*$//' > private_key.pem
- chmod 600 private_key.pem
- ssh-keygen -p -f private_key.pem -m pem -P "" -N ""
- ssh-add private_key.pem
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan github.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config --global user.email "hpc-dr@amazon.com"
- git config --global user.name "GitLab CI - AWS HPC Developer Relations"
script:
- git clone --single-branch --branch main $CI_REPOSITORY_URL repo
- cd repo
- git push --force git@github.com:aws-samples/aws-hpc-recipes.git main:main
retry: 2
after_script:
- rm -f private_key.pem
pull-from-github:
stage: github-pull
image: alpine:latest
when: manual
rules:
- if: $CI_COMMIT_BRANCH == "main"
before_script:
- apk add --no-cache git openssh-client
- eval $(ssh-agent -s)
- echo "${GITHUB_SSH_PRIVATE_KEY}" | tr -d '\r' | sed -e 's/^[ \t]*//' | sed -e 's/[ \t]*$//' > private_key.pem
- chmod 600 private_key.pem
- ssh-keygen -p -f private_key.pem -m pem -P "" -N ""
- ssh-add private_key.pem
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan github.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config --global user.email "hpc-dr@amazon.com"
- git config --global user.name "GitLab CI - AWS HPC Developer Relations"
script:
- git clone --single-branch --branch main "https://${GITLAB_PAT_USERNAME}:${GITLAB_PAT}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" repo
- cd repo
- git remote add github git@github.com:aws-samples/aws-hpc-recipes.git
- git fetch github main
- git merge --no-ff github/main -m "Merge changes from GitHub mirror"
- git push "https://${GITLAB_PAT_USERNAME}:${GITLAB_PAT}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" main
after_script:
- rm -f private_key.pem