|
| 1 | +name: Publish docker images |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | +jobs: |
| 9 | + publish-pypi: |
| 10 | + name: Publish script-runner to pypi |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Publish a Python distribution to PyPI |
| 14 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 15 | + with: |
| 16 | + user: __token__ |
| 17 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 18 | + |
| 19 | + publish-docker: |
| 20 | + name: Publish script-runner to dockerhub |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Check out the repo |
| 24 | + uses: actions/checkout@v2 |
| 25 | + - name: Prepare |
| 26 | + id: prep |
| 27 | + run: | |
| 28 | + PYTHON_IMAGE_TAG=alpine |
| 29 | + DOCKER_IMAGE=labflow/script-runner |
| 30 | + VERSION=latest |
| 31 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 32 | + VERSION=${GITHUB_REF#refs/tags/} |
| 33 | + elif [[ $GITHUB_REF == refs/heads/* ]]; then |
| 34 | + VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') |
| 35 | + elif [[ $GITHUB_REF == refs/pull/* ]]; then |
| 36 | + VERSION=pr-${{ github.event.number }} |
| 37 | + fi |
| 38 | + TAGS="${DOCKER_IMAGE}:${PYTHON_IMAGE_TAG}-latest,${DOCKER_IMAGE}:${PYTHON_IMAGE_TAG}-${VERSION}" |
| 39 | + if [ "${{ github.event_name }}" = "push" ]; then |
| 40 | + TAGS="$TAGS,${DOCKER_IMAGE}:${PYTHON_IMAGE_TAG}-sha-${GITHUB_SHA::8}" |
| 41 | + fi |
| 42 | + echo ::set-output name=version::${VERSION} |
| 43 | + echo ::set-output name=tags::${TAGS} |
| 44 | + echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') |
| 45 | + echo ::set-output name=hashtag::"sha-${GITHUB_SHA::8}" |
| 46 | + echo ::set-output name=pyversion::"${PYTHON_IMAGE_TAG}" |
| 47 | + - name: Set up Docker Buildx |
| 48 | + id: buildx |
| 49 | + uses: docker/setup-buildx-action@v1 |
| 50 | + - name: Cache Docker layers |
| 51 | + uses: actions/cache@v2.1.4 |
| 52 | + with: |
| 53 | + path: /tmp/.buildx-cache |
| 54 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 55 | + restore-keys: | |
| 56 | + ${{ runner.os }}-buildx- |
| 57 | + - name: Login to DockerHub |
| 58 | + if: github.event_name != 'pull_request' |
| 59 | + uses: docker/login-action@v1 |
| 60 | + with: |
| 61 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 62 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 63 | + - name: Push to Docker Hub |
| 64 | + uses: docker/build-push-action@v2 |
| 65 | + with: |
| 66 | + context: ./docker |
| 67 | + file: ./Dockerfile |
| 68 | + builder: ${{ steps.buildx.outputs.name }} |
| 69 | + push: ${{ github.event_name != 'pull_request' }} |
| 70 | + tags: ${{ steps.prep.outputs.tags }} |
| 71 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 72 | + cache-to: type=local,dest=/tmp/.buildx-cache |
| 73 | + labels: | |
| 74 | + org.opencontainers.image.source=${{ github.event.repository.clone_url }} |
| 75 | + org.opencontainers.image.created=${{ steps.prep.outputs.created }} |
| 76 | + org.opencontainers.image.revision=${{ github.sha }} |
| 77 | + build-args: | |
| 78 | + SCRIPT_RUNNER_VERSION=${{ steps.prep.outputs.version }} |
| 79 | + PYTHON_IMAGE_TAG=${{ steps.prep.outputs.pyversion }} |
| 80 | +
|
| 81 | + deploy-aws-example: |
| 82 | + name: Deploy swabseq-analysis-example to AWS |
| 83 | + runs-on: ubuntu-latest |
| 84 | + steps: |
| 85 | + - name: Configure AWS credentials |
| 86 | + uses: aws-actions/configure-aws-credentials@v1 |
| 87 | + with: |
| 88 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 89 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 90 | + aws-region: us-west-1 |
| 91 | + |
| 92 | + - name: Setup Terraform tfvars |
| 93 | + uses: nowactions/envsubst@v1 |
| 94 | + working-directory: ./examples/aws |
| 95 | + with: |
| 96 | + input: ./example.tfvars |
| 97 | + output: ./terraform.tfvars |
| 98 | + env: |
| 99 | + DNS_SUBDOMAIN: ${{secrets.DNS_SUBDOMAIN}} |
| 100 | + DNS_ZONE_ID: ${{secrets.DNS_ZONE_ID}} |
| 101 | + |
| 102 | + - name: Setup Terraform |
| 103 | + working-directory: ./examples/aws |
| 104 | + uses: hashicorp/setup-terraform@v1 |
| 105 | + |
| 106 | + # - name: Terraform Format |
| 107 | + # id: fmt |
| 108 | + # run: terraform fmt -check |
| 109 | + |
| 110 | + - name: Terraform Init |
| 111 | + id: init |
| 112 | + working-directory: ./examples/aws |
| 113 | + run: terraform init |
| 114 | + |
| 115 | + - name: Terraform Plan |
| 116 | + id: plan |
| 117 | + working-directory: ./examples/aws |
| 118 | + if: github.event_name == 'pull_request' |
| 119 | + run: terraform plan -no-color |
| 120 | + continue-on-error: true |
| 121 | + |
| 122 | + - uses: actions/github-script@v3 |
| 123 | + working-directory: ./examples/aws |
| 124 | + if: github.event_name == 'pull_request' |
| 125 | + env: |
| 126 | + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" |
| 127 | + with: |
| 128 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 129 | + script: | |
| 130 | + const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` |
| 131 | + #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` |
| 132 | + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` |
| 133 | +
|
| 134 | + <details><summary>Show Plan</summary> |
| 135 | +
|
| 136 | + \`\`\`${process.env.PLAN}\`\`\` |
| 137 | +
|
| 138 | + </details> |
| 139 | +
|
| 140 | + *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; |
| 141 | +
|
| 142 | +
|
| 143 | + await github.issues.createComment({ |
| 144 | + issue_number: context.issue.number, |
| 145 | + owner: context.repo.owner, |
| 146 | + repo: context.repo.repo, |
| 147 | + body: output |
| 148 | + }) |
| 149 | +
|
| 150 | + - name: Terraform Plan Status |
| 151 | + if: steps.plan.outcome == 'failure' |
| 152 | + run: exit 1 |
| 153 | + |
| 154 | + - name: Terraform Apply |
| 155 | + working-directory: ./examples/aws |
| 156 | + if: (github.event_name == 'release') || (github.event_name == 'push' && github.ref == 'refs/heads/main') |
| 157 | + run: terraform apply -auto-approve |
| 158 | + |
| 159 | + deploy-azure-example: |
| 160 | + name: Deploy swabseq-analysis-example to Azure |
| 161 | + runs-on: ubuntu-latest |
| 162 | + steps: |
| 163 | + - name: Configure Azure credentials |
| 164 | + uses: azure/login@v1 |
| 165 | + with: |
| 166 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 167 | + |
| 168 | + - name: Setup Terraform tfvars |
| 169 | + uses: nowactions/envsubst@v1 |
| 170 | + working-directory: ./examples/azure |
| 171 | + with: |
| 172 | + input: ./example.tfvars |
| 173 | + output: ./terraform.tfvars |
| 174 | + env: |
| 175 | + DNS_SUBDOMAIN: ${{secrets.DNS_SUBDOMAIN}} |
| 176 | + DNS_ZONE_NAME: ${{secrets.DNS_ZONE_NAME}} |
| 177 | + |
| 178 | + - name: Setup Terraform |
| 179 | + working-directory: ./examples/azure |
| 180 | + uses: hashicorp/setup-terraform@v1 |
| 181 | + |
| 182 | + # - name: Terraform Format |
| 183 | + # id: fmt |
| 184 | + # run: terraform fmt -check |
| 185 | + |
| 186 | + - name: Terraform Init |
| 187 | + id: init |
| 188 | + working-directory: ./examples/azure |
| 189 | + run: terraform init |
| 190 | + |
| 191 | + - name: Terraform Plan |
| 192 | + id: plan |
| 193 | + working-directory: ./examples/azure |
| 194 | + if: github.event_name == 'pull_request' |
| 195 | + run: terraform plan -no-color |
| 196 | + continue-on-error: true |
| 197 | + |
| 198 | + - uses: actions/github-script@v3 |
| 199 | + working-directory: ./examples/azure |
| 200 | + if: github.event_name == 'pull_request' |
| 201 | + env: |
| 202 | + PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" |
| 203 | + with: |
| 204 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 205 | + script: | |
| 206 | + const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` |
| 207 | + #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` |
| 208 | + #### Terraform Plan 📖\`${{ steps.plan.outcome }}\` |
| 209 | +
|
| 210 | + <details><summary>Show Plan</summary> |
| 211 | +
|
| 212 | + \`\`\`${process.env.PLAN}\`\`\` |
| 213 | +
|
| 214 | + </details> |
| 215 | +
|
| 216 | + *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; |
| 217 | +
|
| 218 | +
|
| 219 | + await github.issues.createComment({ |
| 220 | + issue_number: context.issue.number, |
| 221 | + owner: context.repo.owner, |
| 222 | + repo: context.repo.repo, |
| 223 | + body: output |
| 224 | + }) |
| 225 | +
|
| 226 | + - name: Terraform Plan Status |
| 227 | + if: steps.plan.outcome == 'failure' |
| 228 | + run: exit 1 |
| 229 | + |
| 230 | + - name: Terraform Apply |
| 231 | + working-directory: ./examples/azure |
| 232 | + if: (github.event_name == 'release') || (github.event_name == 'push' && github.ref == 'refs/heads/main') |
| 233 | + run: terraform apply -auto-approve |
| 234 | + |
0 commit comments