Skip to content

Add secrets support (#748) #479

Add secrets support (#748)

Add secrets support (#748) #479

Workflow file for this run

name: Build, Test and Push Docker Images
on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
jobs:
build:
name: Build Docker Image for Testing
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image for testing
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
load: true
push: false
build-args: SOURCE_COMMIT=${{ github.sha }}
tags: valheim-test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Save Docker image to tarball
run: docker save -o valheim-test.tar valheim-test
- name: Upload Docker image artifact
uses: actions/upload-artifact@v4
with:
name: valheim-test-image
path: valheim-test.tar
retention-days: 1
test:
name: Run Test Matrix
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
config:
- name: default
env: ""
- name: valheim_plus
env: "-e VALHEIM_PLUS=true"
- name: bepinex
env: "-e BEPINEX=true"
steps:
- name: Download Docker image artifact
uses: actions/download-artifact@v4
with:
name: valheim-test-image
- name: Load Docker image from tarball
run: docker load -i valheim-test.tar
- name: Run container with ${{ matrix.config.name }} settings
run: |
docker run -d --rm \
--name valheim-test-${{ matrix.config.name }} \
--cap-add=sys_nice \
--stop-timeout 120 \
-p 2456-2457:2456-2457/udp \
-e SERVER_NAME="My Server" \
-e WORLD_NAME="Neotopia" \
-e SERVER_PASS=secret \
${{ matrix.config.env }} \
valheim-test
docker exec valheim-test-${{ matrix.config.name }} /usr/local/bin/valheim-tests "${{ matrix.config.name }}"
build_and_push:
name: Build and Push Docker Image
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev'
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_PAT }}
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/lloesche/valheim-server
lloesche/valheim-server
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' }}
type=sha
labels: |
org.opencontainers.image.title=valheim-server
org.opencontainers.image.description=Valheim Server
org.opencontainers.image.url=https://github.com/lloesche/valheim-server-docker
org.opencontainers.image.source=https://github.com/lloesche/valheim-server-docker
org.opencontainers.image.version=${{ github.sha }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.documentation=https://github.com/lloesche/valheim-server-docker/blob/main/README.md
annotations: |
org.opencontainers.image.description=Valheim Server
org.opencontainers.image.source=https://github.com/lloesche/valheim-server-docker
org.opencontainers.image.licenses=Apache-2.0
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
build-args: SOURCE_COMMIT=${{ github.sha }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha