You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
7.1 KiB
204 lines
7.1 KiB
--- |
|
name: Build Self-Host Unified |
|
|
|
on: |
|
push: |
|
paths: |
|
- "docker-unified/**" |
|
- ".github/workflows/build-self-host.yml" |
|
workflow_call: |
|
inputs: |
|
server_branch: |
|
type: string |
|
default: master |
|
is_workflow_call: |
|
type: boolean |
|
default: true |
|
workflow_dispatch: |
|
inputs: |
|
server_branch: |
|
description: "Server branch name to deploy (examples: 'master', 'rc', 'feature/sm')" |
|
type: string |
|
default: master |
|
pull_request: |
|
paths: |
|
- ".github/workflows/build-self-host.yml" |
|
- "docker-unified/**" |
|
|
|
jobs: |
|
build-docker: |
|
name: Build Docker image |
|
runs-on: ubuntu-22.04 |
|
steps: |
|
- name: Checkout Repository - workflow_call |
|
if: ${{ inputs.is_workflow_call == true }} |
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 |
|
with: |
|
repository: bitwarden/self-host |
|
ref: master |
|
|
|
- name: Checkout Repository - workflow_dispatch |
|
if: ${{ inputs.is_workflow_call != true }} |
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 |
|
|
|
- name: Get server branch to checkout |
|
id: server-branch-name |
|
env: |
|
SERVER_BRANCH: ${{ inputs.server_branch }} |
|
run: echo "server_branch=${SERVER_BRANCH#refs/heads/}" >> $GITHUB_OUTPUT |
|
|
|
- name: Check Branch to Publish |
|
env: |
|
PUBLISH_BRANCHES: "master,rc,hotfix-rc" |
|
SERVER_BRANCH: ${{ steps.server-branch-name.outputs.server_branch }} |
|
id: publish-branch-check |
|
run: | |
|
if [[ "${{ inputs.is_workflow_call }}" == "true" ]]; then |
|
REF=master |
|
else |
|
REF=${GITHUB_REF#/refs/heads/} |
|
fi |
|
|
|
IFS="," read -a publish_branches <<< $PUBLISH_BRANCHES |
|
|
|
if [[ "${publish_branches[*]}" =~ "${REF}" && "${publish_branches[*]}" =~ "${SERVER_BRANCH}" ]]; then |
|
echo "is_publish_branch=true" >> $GITHUB_ENV |
|
else |
|
echo "is_publish_branch=false" >> $GITHUB_ENV |
|
fi |
|
|
|
########## Set up Docker ########## |
|
- name: Set up QEMU emulators |
|
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0 |
|
|
|
- name: Set up Docker Buildx |
|
uses: docker/setup-buildx-action@4b4e9c3e2d4531116a6f8ba8e71fc6e2cb6e6c8c # v2.5.0 |
|
|
|
########## Login to Docker registries ########## |
|
- name: Login to Azure - QA Subscription |
|
uses: Azure/login@1f63701bf3e6892515f1b7ce2d2bf1708b46beaf # v1.4.3 |
|
with: |
|
creds: ${{ secrets.AZURE_QA_KV_CREDENTIALS }} |
|
|
|
- name: Login to Azure ACR |
|
run: az acr login -n bitwardenqa |
|
|
|
- name: Login to Azure - Prod Subscription |
|
uses: Azure/login@1f63701bf3e6892515f1b7ce2d2bf1708b46beaf # v1.4.3 |
|
with: |
|
creds: ${{ secrets.AZURE_PROD_KV_CREDENTIALS }} |
|
|
|
- name: Login to Azure ACR |
|
run: az acr login -n bitwardenprod |
|
|
|
- name: Login to Azure - CI Subscription |
|
uses: Azure/login@1f63701bf3e6892515f1b7ce2d2bf1708b46beaf # v1.4.3 |
|
with: |
|
creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} |
|
|
|
- name: Retrieve github PAT secrets |
|
id: retrieve-secret-pat |
|
uses: bitwarden/gh-actions/get-keyvault-secrets@c86ced0dc8c9daeecf057a6333e6f318db9c5a2b |
|
with: |
|
keyvault: "bitwarden-ci" |
|
secrets: "github-pat-bitwarden-devops-bot-repo-scope" |
|
|
|
- name: Setup Docker Trust |
|
if: ${{ env.is_publish_branch == 'true' }} |
|
uses: bitwarden/gh-actions/setup-docker-trust@f955298c7a982b3fb5dbb73afd582c584fd5beec |
|
with: |
|
azure-creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} |
|
azure-keyvault-name: "bitwarden-ci" |
|
|
|
########## Generate image tag and build Docker image ########## |
|
- name: Generate Docker image tag |
|
id: tag |
|
env: |
|
SERVER_BRANCH: ${{ steps.server-branch-name.outputs.server_branch }} |
|
run: | |
|
IMAGE_TAG=$(echo "${SERVER_BRANCH}" | sed "s#/#-#g") # slash safe branch name |
|
if [[ "${IMAGE_TAG}" == "master" ]]; then |
|
IMAGE_TAG=dev |
|
fi |
|
|
|
echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT |
|
|
|
- name: Generate tag list |
|
id: tag-list |
|
env: |
|
IMAGE_TAG: ${{ steps.tag.outputs.image_tag }} |
|
IS_PUBLISH_BRANCH: ${{ env.is_publish_branch }} |
|
run: | |
|
if [[ ("${IMAGE_TAG}" == "dev" || "${IMAGE_TAG}" == "beta") && "${IS_PUBLISH_BRANCH}" == "true" ]]; then |
|
echo "tags=bitwardenqa.azurecr.io/self-host:${IMAGE_TAG},bitwardenprod.azurecr.io/self-host:${IMAGE_TAG},bitwarden/self-host:${IMAGE_TAG}" >> $GITHUB_OUTPUT |
|
else |
|
echo "tags=bitwardenqa.azurecr.io/self-host:${IMAGE_TAG},bitwardenprod.azurecr.io/self-host:${IMAGE_TAG}" >> $GITHUB_OUTPUT |
|
fi |
|
|
|
- name: Checkout server repo |
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 |
|
with: |
|
repository: bitwarden/server |
|
token: ${{ steps.retrieve-secret-pat.outputs.github-pat-bitwarden-devops-bot-repo-scope }} |
|
ref: ${{ steps.server-branch-name.outputs.server_branch }} |
|
path: 'server' |
|
|
|
- name: Build and push Docker image |
|
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v3.2.0 |
|
with: |
|
context: . |
|
file: docker-unified/Dockerfile |
|
platforms: | |
|
linux/amd64, |
|
linux/arm/v7, |
|
linux/arm64/v8 |
|
push: true |
|
tags: ${{ steps.tag-list.outputs.tags }} |
|
secrets: | |
|
"GH_PAT=${{ steps.retrieve-secret-pat.outputs.github-pat-bitwarden-devops-bot-repo-scope }}" |
|
|
|
- name: Log out of Docker and disable Docker Notary |
|
if: ${{ env.is_publish_branch == 'true' }} |
|
run: | |
|
docker logout |
|
echo "DOCKER_CONTENT_TRUST=0" >> $GITHUB_ENV |
|
|
|
check-failures: |
|
name: Check for failures |
|
if: always() |
|
runs-on: ubuntu-22.04 |
|
needs: build-docker |
|
steps: |
|
- name: Check if any job failed |
|
if: | |
|
github.ref == 'refs/heads/master' |
|
|| github.ref == 'refs/heads/rc' |
|
|| github.ref == 'refs/heads/hotfix-rc' |
|
env: |
|
BUILD_DOCKER_STATUS: ${{ needs.build-docker.result }} |
|
run: | |
|
if [ "$BUILD_DOCKER_STATUS" = "failure" ]; then |
|
exit 1 |
|
fi |
|
|
|
- name: Login to Azure - CI subscription |
|
uses: Azure/login@1f63701bf3e6892515f1b7ce2d2bf1708b46beaf # v1.4.3 |
|
if: failure() |
|
with: |
|
creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} |
|
|
|
- name: Retrieve secrets |
|
id: retrieve-secrets |
|
uses: bitwarden/gh-actions/get-keyvault-secrets@c86ced0dc8c9daeecf057a6333e6f318db9c5a2b |
|
if: failure() |
|
with: |
|
keyvault: "bitwarden-ci" |
|
secrets: "devops-alerts-slack-webhook-url" |
|
|
|
- name: Notify Slack on failure |
|
uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f # v2.0.0 |
|
if: failure() |
|
env: |
|
SLACK_WEBHOOK_URL: ${{ steps.retrieve-secrets.outputs.devops-alerts-slack-webhook-url }} |
|
with: |
|
status: ${{ job.status }}
|
|
|