log stuff #31
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 Clash of Clans App | |
concurrency: | |
group: build-clash-of-clans-image-${{ github.ref }} | |
cancel-in-progress: true | |
on: | |
pull_request: | |
branches: | |
- main | |
types: [opened, synchronize, reopened, ready_for_review] | |
push: | |
branches: | |
- main | |
jobs: | |
# We are going to build an image specifically for testing and push it to ghcr.io (GitHub Container Registry) | |
# This image is used throught the entire github workflow until it is built for final deployment | |
build-test-image: | |
name: Build Image for Testing | |
runs-on: ubuntu-22.04 | |
permissions: | |
packages: write # Needed to push docker image to ghcr.io | |
contents: read # Needed to read code in repository | |
steps: | |
- id: set-var | |
uses: ASzc/change-string-case-action@v5 | |
with: | |
string: ${{ github.repository }} | |
# Docker buildx is useful for caching images | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
- name: Build and Push Image to ghcr.io | |
uses: docker/build-push-action@v4 | |
with: | |
push: true | |
tags: ghcr.io/${{ steps.set-var.outputs.lowercase }}:test | |
cache-from: type=gha # This will use the cached image from the last time we built it (Caching requires buildx done above) | |
cache-to: type=gha,mode=max # This will cache the image for the next time we build it (max means it will cache all layers) | |
target: development # This is the target stage in the Dockerfile | |
labels: | | |
org.opencontainers.image.title=Test Image | |
org.opencontainers.image.description=Image used for testing | |
org.opencontainers.image.source=ghcr.io/${{ steps.set-var.outputs.lowercase }} | |
# We are going to run unit tests, integration tests, CVE scanning, smoke tests, and linting in parallel | |
lint: | |
name: Lint | |
runs-on: ubuntu-22.04 | |
needs: [build-test-image] | |
permissions: | |
packages: read # Needed to pull docker image from ghcr.io | |
steps: | |
- id: set-var | |
uses: ASzc/change-string-case-action@v5 | |
with: | |
string: ${{ github.repository }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
- name: Run Linting | |
run: docker run --rm ghcr.io/${{ steps.set-var.outputs.lowercase }}:test npm run lint | |
# We are going to build an image specifically for final deployment and push it to ghcr.io (GitHub Container Registry) | |
build-final-image: | |
name: Build Image for Deployment (Staging) | |
runs-on: ubuntu-22.04 | |
needs: [lint] | |
permissions: | |
packages: write # Needed to push docker image to ghcr.io | |
contents: read # Needed to read code in repository | |
steps: | |
- id: set-var | |
uses: ASzc/change-string-case-action@v5 | |
with: | |
string: ${{ github.repository }} | |
# Docker buildx is useful for caching images | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ github.token }} | |
- name: Build and Push Image to ghcr.io | |
uses: docker/build-push-action@v4 | |
with: | |
push: true | |
# Add tags but lowercase the branch name | |
tags: ghcr.io/${{ steps.set-var.outputs.lowercase }}:latest | |
cache-from: type=gha # This will use the cached image from the last time we built it (Caching requires buildx done above) | |
cache-to: type=gha,mode=max # This will cache the image for the next time we build it (max means it will cache all layers) | |
labels: | | |
org.opencontainers.image.title=latest | |
org.opencontainers.image.description=The most recent image built from the main branch | |
org.opencontainers.image.source=ghcr.io/${{ steps.set-var.outputs.lowercase }} | |
clean-old-images: | |
name: Clean Old Images | |
runs-on: ubuntu-latest | |
needs: [build-final-image] | |
permissions: | |
packages: write | |
steps: | |
- uses: actions/delete-package-versions@v4 | |
with: | |
owner: ${{ github.repository_owner }} | |
package-name: ${{ github.event.repository.name }} | |
package-type: container | |
min-versions-to-keep: 5 | |
delete-only-untagged-versions: true |