diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..3ff796f --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,21 @@ + +name: Tests +on: + workflow_dispatch: + push: + branches: + - 'master' + - 'main' + - 'dockerise' + - 'publish-to-dockerhub' + - 'push-to-ghcr-and-ecr' + - 'dockerise-basic' + pull_request: + branches: + - 'master' + - 'main' + - 'dockerise' + - 'publish-to-dockerhub' + - 'push-to-ghcr-and-ecr' + - 'dockerise-basic' +jobs: diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml new file mode 100644 index 0000000..0810811 --- /dev/null +++ b/.github/workflows/ghcr.yml @@ -0,0 +1,48 @@ +# +name: Create and publish a Docker image + +# Configures this workflow to run every time a PR is raised to the branch called `main`. +on: + pull_request: + branches: ['main'] + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/publish-docker-image.yaml b/.github/workflows/publish-docker-image.yaml index 7a40157..56c974f 100644 --- a/.github/workflows/publish-docker-image.yaml +++ b/.github/workflows/publish-docker-image.yaml @@ -4,29 +4,45 @@ on: push: branches: - 'main' +<<<<<<< HEAD - 'master' - 'development' +======= +>>>>>>> dockerise-basic - 'releases/**' jobs: push_to_registry: +<<<<<<< HEAD name: Push Docker image to GHCR +======= + name: Push Docker image to Docker Hub +>>>>>>> dockerise-basic runs-on: ubuntu-latest steps: - name: Check out the repo uses: actions/checkout@v4 +<<<<<<< HEAD - name: Log in to Github Container Registry uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} +======= + - name: Log in to Docker Hub + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} +>>>>>>> dockerise-basic - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: +<<<<<<< HEAD images: ghcr.io/alphagov/re-request-an-aws-account/governmentdigitalservice/ee-request-aws-account tags: | type=sha,enable=true,priority=100,prefix=sha-,suffix=,format=short @@ -39,6 +55,20 @@ jobs: # BUG: This is not echoing locally with `act` - name: Build and push Docker image +======= + images: governmentdigitalservice/ee-request-aws-account + tags: | + type=semver,pattern={{version}} + type=sha,enable=true,priority=100,prefix=sha-,suffix=,format=short + type=raw,value=latest,enable={{is_default_branch}} + + - name: Output tags + run: | + echo "::notice tags: ${{steps.meta.outputs.tags}}" + + - name: Build and push Docker image + id: docker_image +>>>>>>> dockerise-basic uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 with: context: . @@ -46,3 +76,22 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} +<<<<<<< HEAD +======= + + - name: Push Docker image into ECR + uses: docker://ghcr.io/kciter/aws-ecr-action:latest + with: + access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} + secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + account_id: ${{ secrets.AWS_ACCOUNT_ID }} + repo: docker/repo + region: eu-west-2 + tags: latest,${{ github.sha }} + create_repo: true + image_scanning_configuration: true + set_repo_policy: true + repo_policy_file: repo-policy.json + + +>>>>>>> dockerise-basic diff --git a/Dockerfile b/Dockerfile index 483a808..9bee818 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,11 +16,11 @@ COPY . . RUN bundle install RUN npm install - +EXPOSE 3000 # Run a shell #CMD ["bundle", "exec", "rails", "server"] -CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "--port", "8888"] +CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "--port", "3000"]