Merge pull request #128 from digital-land/start-page-content-fixes #250
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: Deploy | |
on: | |
push: | |
branches: [main] | |
workflow_dispatch: | |
inputs: | |
environment: | |
type: environment | |
description: The environment to deploy to. | |
jobs: | |
detect-environments: | |
runs-on: ubuntu-latest | |
outputs: | |
environments: ${{ steps.environments.outputs.result }} | |
steps: | |
- uses: actions/github-script@v6 | |
id: environments | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
result-encoding: json | |
script: | | |
if (context.payload?.inputs?.environment) return [context.payload?.inputs?.environment]; | |
const {data: {environments}} = | |
await github.request(`GET /repos/${process.env.GITHUB_REPOSITORY}/environments`); | |
return environments.map(e => e.name) | |
acceptance-test: | |
runs-on: ubuntu-latest | |
needs: [detect-environments] | |
environment: development | |
env: | |
DOCKER_REPO: ${{ secrets.DEPLOY_DOCKER_REPOSITORY }} | |
steps: | |
- uses: actions/checkout@v4 | |
- id: install-awscli | |
run: | | |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | |
unzip -q awscliv2.zip | |
sudo ./aws/install --update | |
sudo apt-get update | |
sudo apt-get install -y rsync | |
- id: install-node-dependencies | |
run: | | |
npm ci | |
npx playwright install --with-deps | |
- uses: aws-actions/configure-aws-credentials@v1-node16 | |
with: | |
aws-access-key-id: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.DEPLOY_AWS_SECRET_ACCESS_KEY }} | |
aws-region: eu-west-2 | |
- uses: aws-actions/amazon-ecr-login@v1 | |
- id: run-with-docker-compose | |
run: docker compose -f docker-compose-real-backend.yml up -d | |
- id: docker-compose-ps | |
run: | | |
sleep 30 | |
docker compose -f docker-compose-real-backend.yml ps | |
curl -v http://localhost:8085/ | |
- id: run-acceptance-tests | |
run: npm run test:acceptance:ci | |
- uses: actions/upload-artifact@v3 | |
if: always() | |
with: | |
name: playwright-report | |
path: playwright-report/ | |
retention-days: 30 | |
- id: docker-compose-logs | |
if: always() | |
run: | | |
docker compose -f docker-compose-real-backend.yml logs --tail frontend | |
docker compose -f docker-compose-real-backend.yml logs --tail request-api | |
- id: stop-containers | |
if: always() | |
run: docker compose -f docker-compose-real-backend.yml down | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [detect-environments] | |
strategy: | |
matrix: | |
environment: ${{ fromJSON(needs.detect-environments.outputs.environments) }} | |
environment: ${{ matrix.environment }} | |
env: | |
DOCKER_REPO: ${{ secrets.DEPLOY_DOCKER_REPOSITORY }} | |
steps: | |
- uses: actions/checkout@v4 | |
- id: vars | |
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
- run: | | |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | |
unzip -q awscliv2.zip | |
sudo ./aws/install --update | |
sudo apt-get update | |
sudo apt-get install -y rsync | |
- uses: aws-actions/configure-aws-credentials@v1-node16 | |
with: | |
aws-access-key-id: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.DEPLOY_AWS_SECRET_ACCESS_KEY }} | |
aws-region: eu-west-2 | |
- uses: aws-actions/amazon-ecr-login@v1 | |
- run: docker pull $DOCKER_REPO:latest || echo "no current latest image" | |
- run: docker build --build-arg DEPLOY_TIME="$(date +%Y-%m-%dT%H:%M:%S)" --build-arg GIT_COMMIT="${{ steps.vars.outputs.sha_short }}" -t $DOCKER_REPO:${{ steps.vars.outputs.sha_short }} . | |
- run: docker tag $DOCKER_REPO:${{ steps.vars.outputs.sha_short }} $DOCKER_REPO:latest | |
- run: docker push $DOCKER_REPO:${{ steps.vars.outputs.sha_short }} | |
- run: docker push $DOCKER_REPO:latest |