diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7f5c7d5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git +.gitea +node_modules +dist +npm-debug.log* +.env +.env.* diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..b24e75a --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +jobs: + build-frontend: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: npm + + - name: Install deps + run: npm ci + + - name: Build + run: npm run build + + - name: Validate lobby server syntax + run: node --check server/lobby.js diff --git a/.gitea/workflows/docker-publish.yml b/.gitea/workflows/docker-publish.yml new file mode 100644 index 0000000..c49405f --- /dev/null +++ b/.gitea/workflows/docker-publish.yml @@ -0,0 +1,67 @@ +name: Docker Publish + +on: + push: + branches: + - main + tags: + - 'v*' + workflow_dispatch: + +env: + REGISTRY: gitea.theriise.net + IMAGE_WEB: gitea.theriise.net/steinhelge/pong-web + IMAGE_LOBBY: gitea.theriise.net/steinhelge/pong-lobby + +jobs: + publish-images: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set image tags + id: meta + shell: bash + run: | + short_sha="$(git rev-parse --short=12 HEAD)" + echo "short_sha=$short_sha" >> "$GITHUB_OUTPUT" + if tag_name="$(git describe --tags --exact-match 2>/dev/null)"; then + echo "version_tag=$tag_name" >> "$GITHUB_OUTPUT" + else + echo "version_tag=sha-$short_sha" >> "$GITHUB_OUTPUT" + fi + + - name: Login to registry + shell: bash + env: + REGISTRY_USER: ${{ secrets.REGISTRY_USER }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + run: | + test -n "$REGISTRY_USER" + test -n "$REGISTRY_PASSWORD" + echo "$REGISTRY_PASSWORD" | docker login "$REGISTRY" -u "$REGISTRY_USER" --password-stdin + + - name: Build and push web image + shell: bash + run: | + docker build \ + -f Dockerfile \ + -t "$IMAGE_WEB:${{ steps.meta.outputs.version_tag }}" \ + -t "$IMAGE_WEB:latest" \ + . + docker push "$IMAGE_WEB:${{ steps.meta.outputs.version_tag }}" + docker push "$IMAGE_WEB:latest" + + - name: Build and push lobby image + shell: bash + run: | + docker build \ + -f Dockerfile.lobby \ + -t "$IMAGE_LOBBY:${{ steps.meta.outputs.version_tag }}" \ + -t "$IMAGE_LOBBY:latest" \ + . + docker push "$IMAGE_LOBBY:${{ steps.meta.outputs.version_tag }}" + docker push "$IMAGE_LOBBY:latest"