Replace setup-cd-tools with a custom action #75
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: cicd | |
on: | |
push: | |
branches: | |
- development | |
- master | |
pull_request: | |
branches: | |
- development | |
- master | |
jobs: | |
test: | |
runs-on: ubuntu-20.04 | |
env: | |
DOCKER_BUILDKIT: "1" | |
COMPOSE_DOCKER_CLI_BUILD: "1" | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: docker/setup-buildx-action@v3 | |
- run: docker compose -f docker-compose.test.yml up --exit-code-from test | |
build: | |
runs-on: ubuntu-20.04 | |
env: | |
SKAFFOLD_DEFAULT_REPO: ghcr.io/con2 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- uses: ./.github/cache-tools | |
- uses: docker/login-action@v3 | |
if: ${{ github.event_name == 'push' }} | |
with: | |
registry: ghcr.io | |
username: ${{ secrets.GHCR_USERNAME }} | |
password: ${{ secrets.GHCR_PASSWORD }} | |
- uses: docker/setup-buildx-action@v3 | |
- id: build | |
run: | | |
python3 -m pip install emskaffolden | |
# Do not push to registry on pull request events | |
if [ "${{ github.event_name }}" = pull_request ]; then | |
EMSKAFFOLDEN_ENV=pull_request | |
else | |
EMSKAFFOLDEN_ENV=default | |
fi | |
emskaffolden -E "$EMSKAFFOLDEN_ENV" -- build --file-output build.json | |
echo "build_json=$(base64 -w 0 < build.json)" >> "$GITHUB_OUTPUT" | |
outputs: | |
build_json: ${{ steps.build.outputs.build_json }} | |
# TODO DRY | |
deploy_staging: | |
runs-on: self-hosted | |
needs: build | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- uses: ./.github/cache-tools | |
- uses: docker/setup-buildx-action@v3 | |
- run: | | |
python3 -m pip install emskaffolden | |
base64 -d <<< "${{ needs.build.outputs.build_json }}" > build.json | |
emskaffolden -E staging -- deploy -n kirppu-staging -a build.json | |
deploy_production: | |
runs-on: self-hosted | |
needs: build | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- uses: ./.github/cache-tools | |
- uses: docker/setup-buildx-action@v3 | |
- run: | | |
python3 -m pip install emskaffolden | |
base64 -d <<< "${{ needs.build.outputs.build_json }}" > build.json | |
emskaffolden -E production -- deploy -n kirppu -a build.json |