Guilamb is building and deploying the app 🏗️ #16
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: Build and Deploy | |
run-name: ${{ github.actor }} is building and deploying the app 🏗️ | |
on: | |
push: | |
# If we specify branches: [main] here it will run for any matching tags or push on branch main | |
tags: ['v[0-9].[0-9]+.[0-9]+'] | |
workflow_dispatch: | |
permissions: | |
users: | |
- github.repository_owner | |
jobs: | |
build-musl: | |
runs-on: ubuntu-latest | |
# So we need to put the condition in the if here | |
if: ${{ (github.actor == github.event.repository.owner.login) && (github.ref == 'refs/heads/main') }} | |
steps: | |
- name: Run sccache-cache | |
uses: mozilla-actions/sccache-action@v0.0.3 | |
- uses: actions/checkout@v3 | |
- run: rustup target add x86_64-unknown-linux-musl | |
- name: Install musl build tools | |
run: sudo apt update && sudo apt install musl-tools -y | |
- name: Cargo build | |
env: | |
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} | |
run: cargo build --release --target x86_64-unknown-linux-musl | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.REGISTRY_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: Dockerfile | |
push: true | |
tags: | | |
ghcr.io/guilamb/interspecies-reviewer:latest | |
ghcr.io/guilamb/interspecies-reviewer:${{ github.run_number }} | |
secrets: | | |
"github_token=${{ secrets.REGISTRY_TOKEN }}" | |
deploy: | |
needs: build-musl | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set secret as environment variable | |
env: | |
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} | |
run: echo "DISCORD_TOKEN=$DISCORD_TOKEN" >> $GITHUB_ENV | |
- name: Substitute secret in deployment YAML | |
run: | | |
envsubst < deployment.yaml > deployment_with_secret.yaml | |
- name: Deploy to Kubernetes | |
run: kubectl apply -f deployment_with_secret.yaml |