|
| 1 | +name: CI to ECR |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: [feature/ci,develop] |
| 5 | + |
| 6 | +jobs: |
| 7 | + docker-build-push: |
| 8 | + # Name the Job |
| 9 | + name: Build and push |
| 10 | + runs-on: build |
| 11 | + outputs: |
| 12 | + repository: ${{ steps.build.outputs.repository }} |
| 13 | + image_tag: ${{ steps.build.outputs.image_tag }} |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v2 |
| 16 | + - name: Configure AWS credentials |
| 17 | + id: checkout |
| 18 | + uses: aws-actions/configure-aws-credentials@v1 |
| 19 | + with: |
| 20 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 21 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 22 | + aws-region: ${{ secrets.AWS_REGION }} |
| 23 | + - name: Login to Amazon ECR |
| 24 | + id: login-ecr |
| 25 | + uses: aws-actions/amazon-ecr-login@v1 |
| 26 | + - name: Build, tag, and push image to AWS ECR |
| 27 | + id: build |
| 28 | + env: |
| 29 | + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 30 | + ECR_REPOSITORY: velas-synapse |
| 31 | + IMAGE_TAG: ${{github.sha}} |
| 32 | + run: | |
| 33 | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --no-cache -f docker/Dockerfile . |
| 34 | + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
| 35 | + echo "::set-output name=repository::$ECR_REPOSITORY" |
| 36 | + echo "::set-output name=image_tag::$IMAGE_TAG" |
| 37 | + deploy: |
| 38 | + name: Deploy via Helmfile |
| 39 | + runs-on: deploy |
| 40 | + needs: docker-build-push |
| 41 | + steps: |
| 42 | + - name: Configure AWS credentials |
| 43 | + id: checkout |
| 44 | + uses: aws-actions/configure-aws-credentials@v1 |
| 45 | + with: |
| 46 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 47 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 48 | + aws-region: ${{ secrets.AWS_REGION }} |
| 49 | + - name: Login to Amazon ECR |
| 50 | + id: login-ecr |
| 51 | + uses: aws-actions/amazon-ecr-login@v1 |
| 52 | + - name: Setup helmfile |
| 53 | + uses: mamezou-tech/[email protected] |
| 54 | + with: |
| 55 | + helmfile-version: "v0.131.0" |
| 56 | + - name: Check out velas-infra |
| 57 | + uses: actions/checkout@master |
| 58 | + with: |
| 59 | + repository: velas/velas-infra |
| 60 | + ssh-key: ${{ secrets.INFRA_SSH_KEY }} |
| 61 | + - name: Deploy via helmfile |
| 62 | + id: deploy |
| 63 | + env: |
| 64 | + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 65 | + ECR_REPOSITORY: ${{ needs.docker-build-push.outputs.repository }} |
| 66 | + IMAGE_TAG: ${{ needs.docker-build-push.outputs.image_tag }} |
| 67 | + KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA_DEV }} |
| 68 | + NAMESPACE: devnet |
| 69 | + run: | |
| 70 | + if [ `helm plugin list|grep diff|wc -l` -eq '0' ]; then helm plugin install https://github.com/databus23/helm-diff ; fi |
| 71 | + if [ ${GITHUB_REF##*/} = 'master' ]; then NAMESPACE=default; fi |
| 72 | + mkdir -p ~/.kube && echo $KUBE_CONFIG_DATA|base64 --decode > ~/.kube/config |
| 73 | + cd deploy |
| 74 | + helmfile -e dev -l namespace=${NAMESPACE},name=velas-synapse apply --set image.tag=$IMAGE_TAG,image.repository=$ECR_REGISTRY/$ECR_REPOSITORY --skip-deps |
| 75 | +
|
0 commit comments