Docker Image CI #237
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: Docker Image CI | |
on: | |
schedule: | |
- cron: "0 05 * * *" | |
push: | |
branches: | |
- "master" | |
tags: | |
- "v*.*.*" | |
pull_request: | |
branches: | |
- "master" | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: xenira/space3 | |
CARGO_TERM_COLOR: always | |
DOCKER_BUILDKIT: '1' | |
TAG: ${{ github.sha }} | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Docker metadata | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
# list of Docker images to use as base name for tags | |
images: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
# generate Docker tags based on the following events/attributes | |
tags: | | |
type=schedule | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
type=sha | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to the Container registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: build | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
outputs: | |
version: ${{ steps.meta.outputs.version }} | |
deploy-prev: | |
if: github.event_name == 'push' && github.ref == 'refs/heads/master' | |
name: Deploy to preview | |
needs: build | |
environment: | |
name: preview | |
url: https://prev-game.3.141.rip | |
runs-on: ubuntu-latest | |
steps: | |
- name: Invoke deployment hook | |
uses: distributhor/workflow-webhook@v3 | |
env: | |
webhook_url: ${{ secrets.WEBHOOK_URL }} | |
webhook_secret: ${{ secrets.WEBHOOK_SECRET }} | |
data: '{ "tag": "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:master" }' | |
deploy-prod: | |
if: github.event_name == 'push' && github.ref == 'refs/tags/v*.*.*' | |
name: Deploy to production | |
needs: build | |
environment: | |
name: live | |
url: https://game.3.141.rip | |
runs-on: ubuntu-latest | |
steps: | |
- name: Invoke deployment hook | |
uses: distributhor/workflow-webhook@v3 | |
env: | |
webhook_url: ${{ secrets.WEBHOOK_URL }} | |
webhook_secret: ${{ secrets.WEBHOOK_SECRET }} | |
data: '{ "tag": "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build.outputs.version }}" }' |